[Haskell-beginners] Here's why functions should return functions

Ertugrul Söylemez es at ertes.de
Sun Jul 29 16:55:06 CEST 2012


Thiago Negri <evohunz at gmail.com> wrote:

> @Ertugrul, you don't need to be rude.

Sorry if this sounded rude, but it really wasn't supposed to be.  As
said, I liked Costello's attempt.  I just found that the solution is
already in the base library in a way that doesn't require wrapping
things up in a constructor.


> @Costello,
>
> I like your idea. But I don't see an advantage to using "Function 4"
> over simply "4":
>
> What's the advantage of using this:
>     (value . square . sucessor . lift) 4
>     data Lift a = Function a
>     lift = Function
>     sucesor (Function a) = lift (a + 1)
>     square (Function a) = lift (a * a)
>     value (Function a) = a
>
> Over this:
>     (square . sucessor) 4
>     sucessor = (+1)
>     square a = a * a

I think that Costello is really referring to something called
function-level programming where you don't have values, but only
so-called functionals and composition.  A value is then represented by a
constant function, which is exactly what 'const' and 'pure' are.

This is the essence of SKI calculus.  It gets rid of all lambda
abstractions.  The remainder is then an (unintelligible) expression of S
and K applications, but Haskell also has the power of Category, so this
can actually become readable code.


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/20120729/1583282c/attachment.pgp>


More information about the Beginners mailing list