Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lets.Lens: type of modify incompatible with Prisms? #11

Open
endgame opened this issue May 10, 2018 · 0 comments
Open

Lets.Lens: type of modify incompatible with Prisms? #11

endgame opened this issue May 10, 2018 · 0 comments

Comments

@endgame
Copy link

endgame commented May 10, 2018

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 ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant