Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Literate Haskell - capturing output (Martin Drautzburg)
   2. Re:  f . g or f g  or f $ g? (Ertugrul S?ylemez)
   3. Re:  f . g or f g  or f $ g? (Brent Yorgey)
   4. Re:  f . g or f g or f $ g? (Denis Kasak)
   5. Re:  Using Parsec to parse Haskell Language (Henk-Jan van Tuyl)


----------------------------------------------------------------------

Message: 1
Date: Fri, 1 Feb 2013 22:23:01 +0100
From: Martin Drautzburg <martin.drautzb...@web.de>
Subject: Re: [Haskell-beginners] Literate Haskell - capturing output
To: beginners@haskell.org
Message-ID: <201302012223.01336.martin.drautzb...@web.de>
Content-Type: Text/Plain;  charset="iso-8859-15"

On Thursday, 31. January 2013 15:25:56 Rustom Mody wrote:

> If you are ok with emacs,
> emacs -> orgmode -> babel may be worth a consider
> http://orgmode.org/worg/org-contrib/babel/intro.html
> http://www.jstatsoft.org/v46/i03/paper

Yes, I'm okay with emacs and I use org-mode a lot. Can you point be to an 
example of using org-mode with haskell? I've only seen that as a way to add 
program output to a documentation, but will I still end up with a runnable 
haskell program?
-- 
Martin



------------------------------

Message: 2
Date: Fri, 1 Feb 2013 23:02:39 +0100
From: Ertugrul S?ylemez <e...@ertes.de>
Subject: Re: [Haskell-beginners] f . g or f g  or f $ g?
To: beginners@haskell.org
Message-ID: <20130201230239.49eac...@tritium.streitmacht.eu>
Content-Type: text/plain; charset="us-ascii"

Martin Drautzburg <martin.drautzb...@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

Indeed:

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

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

I hope this helps. =)


Greets,
Ertugrul

-- 
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-0001.pgp>

------------------------------

Message: 3
Date: Fri, 1 Feb 2013 17:04:44 -0500
From: Brent Yorgey <byor...@seas.upenn.edu>
Subject: Re: [Haskell-beginners] f . g or f g  or f $ g?
To: beginners@haskell.org
Message-ID: <20130201220444.ga19...@seas.upenn.edu>
Content-Type: text/plain; charset=us-ascii

On Fri, Feb 01, 2013 at 08:42:56PM +0100, Martin Drautzburg wrote:
> 
> Is there a way to easily remember when to use f.g and when to use f g without 
> having to do this type algebra.

No.

After enough practice, however, this sort of type algebra becomes
second nature, and no longer requires much conscious effort.

-Brent



------------------------------

Message: 4
Date: Fri, 1 Feb 2013 23:12:23 +0100
From: Denis Kasak <denis.ka...@gmail.com>
Subject: Re: [Haskell-beginners] f . g or f g or f $ g?
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Message-ID:
        <canjrnzcn1a1zjnzhchjyfbapd4ihetr6edaydewabhmo7m1...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On 1 February 2013 20:42, Martin Drautzburg <martin.drautzb...@web.de>wrote:

> Hello all
>
> I frequently get confused over f . g vs f g. I do understand the following
>
> With:
>
> g :: a->b
> f :: b ->c
>
> f.g :: a->c
>
> However
>
> f g
>
> is a type error, because then f would have to accept a function (a->b) as
> its
> first parameter, but it only accepts a b.
>
> Is there a way to easily remember when to use f.g and when to use f g
> without
> having to do this type algebra.
>

If you're familiar with the analogous operations in mathematics (function
composition and function application), it should be easy to reason about.

Function application is the act of "calling" the function: passing it an
argument and making it "return" a result. In math, we write function
application with parentheses, i.e.

    cos(pi)

which "returns" (or /has value of/) -1. The equivalent in Haskell would be
written simply as

    cos pi

Function composition on the other hand is the act of combining two
functions (e.g. f1 and f2) so that the resultant function performs both
operations in sequence. You can think of it as combining the functions in a
pipeline so that the output of the first is passed as an argument to the
second. Again, in mathematics, we'd write the composition of f1 and f2 as

    f2 ? f1

In Haskell, we would write the same as

    f2 . f1

This is a good mnemonic for remembering the role of (.) since the dot looks
a bit like the small circle used for functional composition in mathematics.

-- 
Denis Kasak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130201/453347af/attachment-0001.htm>

------------------------------

Message: 5
Date: Fri, 01 Feb 2013 23:55:56 +0100
From: "Henk-Jan van Tuyl" <hjgt...@chello.nl>
Subject: Re: [Haskell-beginners] Using Parsec to parse Haskell
        Language
To: beginners@haskell.org, "Sean Cormican" <seancormic...@gmail.com>
Message-ID: <op.wrunbinjpz0...@zen5.arnhem.chello.nl>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
        delsp=yes

On Thu, 31 Jan 2013 17:40:49 +0100, Sean Cormican  
<seancormic...@gmail.com> wrote:

> I'm working on a project in which I am attempting to write a parser for
> Haskell within Haskell itself using Parsec.

Do you know about the haskell-src package[0]? As you didn't receive any  
answer to your questions yet, I suggest you ask them on Haskell cafe, as  
there are more experts there.

Regards,
Henk-Jan van Tuyl


[0] http://hackage.haskell.org/package/haskell-src

-- 
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--



------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 56, Issue 4
****************************************

Reply via email to