I've encountered a problem of using Control.Lens
together with
datatypes while using the -XTypeFamilies
GHC pragma.
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
import Control.Lens (makeLenses)
class SomeClass t where
data SomeData t :: * -> *
data MyData = MyData Int
instance SomeClass MyData where
data SomeData MyData a = SomeData {_a :: a, _b :: a}
makeLenses ''SomeData
The error message is: reifyDatatype: Use a value constructor to reify a data family instance
.
Is there any way to overcome it, maybe using some functional from Control.Lens
?
The most sensible thing would be to just define those lenses yourself... it's not like it's very difficult:
a, b :: Lens' (SomeData MyData a) a
a = lens _a (\s a' -> s{_a=a'})
b = lens _b (\s b' -> s{_b=b'})
or even
a, b :: Functor f => (a -> f a) -> SomeData MyData a -> f (SomeData MyData a)
a f (SomeData a₀ b₀) = (`SomeData`b₀) <$> f a₀
b f (SomeData a₀ b₀) = SomeData a₀ <$> f b₀
...which doesn't use anything from the lens library at all, but is fully compatible to all lens combinators.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With