[Haskell-beginners] Here's why functions should return functions
Thiago Negri
evohunz at gmail.com
Sun Jul 29 15:45:22 CEST 2012
@Ertugrul, you don't need to be rude.
@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
For me, it looks like we are wrapping a value inside a container and
dewrapping it every time we want to use it's value, then rewrap to
return.
Could you elaborate an example that your Lift a datatype is better
suited than just the raw value?
I can only see the use of a value lifted as a function when you want
to get the same result no matter what are the chain of functions, for
example, the use of the const function:
const 4 . square . sucessor $ 4
Thiago.
More information about the Beginners
mailing list