On 2012.06.13, at 17:44, Francesco Lazzarino wrote:
> this guy from work was trying to explain to me that all values in
> haskell are unapplied functions.
I'm not sure, but it seems trueish.
I usually read "4::Int" as "4 is an Int" but another way that might be
better is "a function named 4 that takes nothing and returns Int".
> mul :: Int -> Int -> Int
> mul x y = x * y
^ When we look at mul, because we grew up with "int mul(int x, int y)",
we tend to think it's a function that takes two Ints and returns Int.
But we could also think of it as a function that takes no arguments and
returns an anonymous function ::Int->Int->Int, or as a function that
takes Int and returns a function from Int to Int (i.e., ::Int->Int).
> double :: Int -> Int
> double = mul 2
^ double is mul partially applied. Like we said above, we gave mul one
Int and it gave us back a function from Int to Int.
> ten :: Int
> ten = double 5
^ If we apply it again, we get back Int. Or we could say we get back a
function that takes no arguments that returns Int.
But I'm still not sure about what the guy said.
> seven :: Int
> seven = 7
^ I think I can agree that this is partially applied. To get its value,
you need to call it and apply it the nothing that it "needs".
But 4 is not a valid name for a function. You can't define, e.g., 4=4.
So I don't think 4 is really a function, although it might still be
useful to think of it like that.
Put another way, I think we know the compiler is not really storing
anything like "4" -> {how to compute 4} when it encounters 4::Int. But
it does seem like an elegant way to think of it.