[Haskell-beginners] f . g or f g or f $ g?

Ertugrul Söylemez es at ertes.de
Fri Feb 1 23:02:39 CET 2013

Martin Drautzburg <Martin.Drautzburg at web.de> wrote:

> I frequently get confused over f . g vs f g. I do understand the
> following

Out of the three choices "f . g", "f g" and "f $ g", only the dot
operator has a special meaning.  The others are the same thing.
Remember the function composition operator from math?  It's the circle
operator.  That's how you should read the dot.  In fact, if you use
Emacs, you can make it display the dot that way.  The haskell-mode has
this built in.

    (f . g) x = f (g x)

There is also something interesting to note about application:

    f $ x   = ($) f x
    ($) f x = f x

From that follows:

    ($) f = f

And from that follows:

    ($) = id


    id  :: a        -> a
    ($) :: (a -> b) -> (a -> b)

($) is really just id with a more special type.

I hope this helps. =)


Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130201/9857b09c/attachment.pgp>

More information about the Beginners mailing list