everything is an partially applied function

7 views
Skip to first unread message

Francesco Lazzarino

unread,
Jun 13, 2012, 8:44:20 PM6/13/12
to gainesvil...@googlegroups.com
this guy from work was trying to explain to me that all values in haskell are unapplied functions.

as in 4 :: Int is a partially applied function called Int

can you guys explain this? i thought 4 was an Int, a piece of memory with some info attached to it describing it as an int.

Francesco Lazzarino

unread,
Jun 13, 2012, 9:25:25 PM6/13/12
to gainesvil...@googlegroups.com
i think he was confusing a partially applied function with a thunk

Brian Lewis

unread,
Jun 14, 2012, 5:23:26 AM6/14/12
to gainesvil...@googlegroups.com
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.

Ian Taylor

unread,
Jun 14, 2012, 12:47:02 PM6/14/12
to gainesvil...@googlegroups.com
On 6/13/12 8:44 PM, Francesco Lazzarino wrote:
> this guy from work was trying to explain to me that all values in
> haskell are unapplied functions.
> as in 4 :: Int is a partially applied function called Int
In Haskell, all values are not unapplied functions. That said, you can
encode values into the lambda calculus where that is true (not going to
show this).

In Haskell, you can think of all functions as being functions of one
argument. Functions that appear to take multiple arguments are just
functions of one argument that return functions (partial application of
curried functions).
> can you guys explain this? i thought 4 was an Int, a piece of memory
> with some info attached to it describing it as an int.
So, I think you're talking about the cost of parametric polymorphism and
boxing vs unboxing. If you have a literal '4' hanging out or a name
bound to it, then no, I believe the compiler can throw away the typing
information at compile time.

Francesco Lazzarino

unread,
Jun 14, 2012, 10:51:43 PM6/14/12
to gainesvil...@googlegroups.com
ok i talked to the guy today and he just meant that you can partially apply a function, nothing crazy about what a 0-arity constructor means.

glad to hear from your guys, everything going well?


On Wednesday, June 13, 2012 7:44:20 PM UTC-5, Francesco Lazzarino wrote:
Reply all
Reply to author
Forward
0 new messages