[Haskell-beginners] ap = liftM2 id

Andres Löh andres at well-typed.com
Thu Mar 26 20:33:46 UTC 2015


There's no such thing as a fixed arity of a function in Haskell. The
type of id is

> id :: a -> a

If you instantiate "a" with "b -> c", then it becomes

> id :: (b -> c) -> b -> c

and it suddenly takes two arguments. In fact, it then behaves like
function application. Try

> id not True

or

> not `id` True

and you'll see that it works as if you had used function application
or $ instead. So ap lifts function application, and if it helps, you
can think of it as instead being defined as

> ap = liftM2 ($)

Cheers,
  Andres


On Thu, Mar 26, 2015 at 9:18 PM, martin <martin.drautzburg at web.de> wrote:
> Hello all,
>
> can someone explain
>
> ap  =  liftM2 id
>
> to me? liftM2 wants a binary funcation
>
> liftM2  :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
>
> but id is unary. How does this work?
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



-- 
Andres Löh, Haskell Consultant
Well-Typed LLP, http://www.well-typed.com

Registered in England & Wales, OC335890
250 Ice Wharf, 17 New Wharf Road, London N1 9RF, England


More information about the Beginners mailing list