haskell - When does GHCI not deduce the required context? -




why ghci add constraint required context here:

> let f = fmap show  > :t f f :: (functor f, show a) => f -> f string 

but not here?

> :t on over :: lens s t b -> (a -> b) -> s -> t  > :t _all' _all' :: (applicative f, eq a) => -> (a -> f a) -> [a] -> f [a]  > :t on (_all' 2)  <interactive>:1:7: error:     • not deduce (applicative f) arising use of ‘_all'’ 

is there major difference between these 2 cases?

note isn't type of over defined lens library. being said, version doesn't work because lens is

type lens = forall f. functor f => (a -> f b) -> s -> f t 

and

_all' 2 :: forall f. applicative f => .. 

in other words, over demanding function works functor, you've provided 1 works applicative (which stronger constraint, in functor doesn't imply applicative).

comment @user2407038.

as alluded in comment, can fix problem fixing type signature over. should either complicated fancy thing in lens using distributive functors or simpler

type setter s t b = (a -> identity b) -> s -> identity t on :: setter s t b -> (a -> b) -> s -> t 

as identity type both functor , applicative, unifies lenses , (i assume in case) traversals.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -