[Haskell-cafe] Help with identity functor print instance and monad transformers

Cody Goodman codygman.consulting at gmail.com
Thu Jan 22 23:31:39 UTC 2015


Thanks for the help!
On Jan 22, 2015 5:03 PM, "wren romano" <winterkoninkje at gmail.com> wrote:

> On Tue, Jan 20, 2015 at 12:09 AM, Cody Goodman
> <codygman.consulting at gmail.com> wrote:
> > I understand the error below, but I'm not really sure what an instance of
> > liftIO would look like for the Identity functor. I guess I'm not all to
> > clear on what an identity functor is.
> >
> > I'm a little fuzzy on what an identity monad is. I understand that id
> gives
> > the identity of something back pretty well though. Can anyone help?
>
> The identity functor/monad is this:
>
>     newtype Identity a = Identity { runIdentity :: a }
>
> That is, the type constructor `Identity` works like the function `id`,
> but on the type level. It doesn't add any sort of special effects, it
> just gives us a type constructor that we can use whenever we need
> something of kind * -> *, like when working with monad transformer
> stacks.
>
> Identity is trivially a monad:
>
>     instance Functor Identity where
>         fmap f (Identity x) = Identity (f x)
>
>     instance Applicative Identity where
>         pure x = Identity x
>         Identity f <*> Identity x = Identity (f x)
>
>     instance Monad Identity where
>         return x = Identity x
>         Identity x >>= f = f x
>
> If we erase all the newtype un/wrapping, then we can see that all
> these functions are just variations on ($) and `id`. That's why we say
> it's trivial.
>
> --
> Live well,
> ~wren
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20150122/20a60e9b/attachment.html>


More information about the Haskell-Cafe mailing list