I have a simple polymorphic data type Foo
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
data Foo c =
Foo {
_bar :: c,
_baz :: c,
_quux :: c
}
makeLenses ''Foo
The generated lenses are, of course, polymorphic in c. Type from GHCi:
*Main> :t bar
bar :: Functor f => (c0 -> f c0) -> Foo c0 -> f (Foo c0)
I made a data type Blahto wrap around the lens. This works great in simple cases (with extension RankNTypes, of course):
data Blah = Blah (forall c . Lens' (Foo c) c)
orange :: Blah
orange = Blah bar
But something a little more complicated does not work, for example
cheese :: [Blah]
cheese = map Blah [bar]
This last piece of code gives an error from the GHC:
Couldn't match type โ(c0 -> f0 c0) -> Foo c0 -> f0 (Foo c0)โ
with โforall c (f :: * -> *).
Functor f =>
(c -> f c) -> Foo c -> f (Foo c)โ
Expected type: ((c0 -> f0 c0) -> Foo c0 -> f0 (Foo c0)) -> Blah
Actual type: (forall c. Lens' (Foo c) c) -> Blah
In the first argument of โmapโ, namely โBlahโ
In the expression: map Blah [bar]
It seems to have forall c f .disappeared from โ(c0 -> f0 c0) -> Foo c0 -> f0 (Foo c0)โ, but I do not understand why.
Why doesn't this compile and what can I do to make something like this work?
source
share