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
overdefined lens library. being said, version doesn't work becauselensistype lens = forall f. functor f => (a -> f b) -> s -> f tand
_all' 2 :: forall f. applicative f => ..in other words,
overdemanding function worksfunctor, you've provided 1 worksapplicative(which stronger constraint, infunctordoesn't implyapplicative).
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
Post a Comment