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

Costello, Roger L. costello at mitre.org
Sun Jul 29 16:30:59 CEST 2012


Thiago Negri wrote:

> What's the advantage of using this:
>     (value . square . successor . lift) 4
>     data Lift a = Function a
>     lift = Function
>     successor (Function a) = lift (a + 1)
>     square (Function a) = lift (a * a)
>     value (Function a) = a
>
> Over this:
>     (square . successor) 4
>     successor = (+1)
>    square a = a * a

Oops!

There's no advantage, that I can see, of the former over the latter.

Thanks Thiago for pointing this out. This is very helpful. It helps me to avoid continuing on a wrong course of thought.

/Roger



More information about the Beginners mailing list