[Haskell-beginners] which Applicative instance?

Kim-Ee Yeoh 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]
> [1,2,3,4,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

https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/interactive-evaluation.html#actions-at-prompt

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.

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151115/8cda6739/attachment-0001.html>


More information about the Beginners mailing list