[Haskell-beginners] which Applicative instance?
ky3 at atamo.com
Sun Nov 15 02:58:04 UTC 2015
On Sun, Nov 15, 2015 at 9:29 AM, Graham Gill <math.simplex at gmail.com> wrote:
> More simply
> > :t pure
> pure :: Applicative f => a -> f a
> > pure [1..5]
> a must match a list of Nums, but then where did f go? Is ghci using some
> default instance?
Yes it is. The default instance is IO. It's a common gotcha, see
and the example of how "return True" defaults to IO Bool.
Might I compliment you on this:
sequenceA' :: Applicative f => [f a] -> f [a]
sequenceA' = foldr (\fa fla -> (:) <$> fa <*> fla) (pure )
There are strong arguments that this is the best way of writing sequenceA.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners