In Lets.Lens, modify has the following type signature:
modify :: Lens s t a b -> (a -> b) -> s -> t
This is fine until the final exercise, which seems to want me to use a Prism with modify:
intOrLengthEven :: IntOr [a] -> IntOr Bool
intOrLengthEven = modify intOrP (even . length)
This fails with the following type error:
src/Lets/Lens.hs:756:26: error:
• Could not deduce (Applicative f) arising from a use of ‘intOrP’
from the context: Functor f
bound by a type expected by the context:
Lens (IntOr [a]) (IntOr Bool) [a] Bool
at src/Lets/Lens.hs:756:19-47
Possible fix:
add (Applicative f) to the context of
a type expected by the context:
Lens (IntOr [a]) (IntOr Bool) [a] Bool
• In the first argument of ‘modify’, namely ‘intOrP’
In the expression: modify intOrP (even . length)
In an equation for ‘intOrLengthEven’:
intOrLengthEven = modify intOrP (even . length)
|
756 | intOrLengthEven = modify intOrP (even . length)
| ^^^^^^
Changing the type of modify to modify :: Set s t a b -> (a -> b) -> s -> t fixes this problem. I note that lens uses this type for over :: ASetter s t a b -> (a -> b) -> s -> t (because type ASetter s t a b = (a -> Identity b) -> s -> Identity t ).
In
Lets.Lens,modifyhas the following type signature:This is fine until the final exercise, which seems to want me to use a
Prismwithmodify:This fails with the following type error:
Changing the type of
modifytomodify :: Set s t a b -> (a -> b) -> s -> tfixes this problem. I note thatlensuses this type forover :: ASetter s t a b -> (a -> b) -> s -> t(becausetype ASetter s t a b = (a -> Identity b) -> s -> Identity t).