constants and functions without arguments
Hi, I hope this is the right forum to post my question to. Given a lazy pure functional language do we need to differntiate (in syntax) between constants and functions without agruments? And if we don't need to, does Haskell make a difference? In a language with eager evaluation (let's take SML) we must differentiat. Given we have a function that takes one argument of type int, is different than a function that takes unit->int. Because of that in SML, whenever I have a function (say "h") that takes an int, and I want to apply a function (without arguments), let's call it g) on it I need to add "()" at the end. h g() but for any constant i of type int I write: h i Now, this leads to my question: In a lazy language do I need to write those "()", or could the compiler tell the difference and always do the correct thing? many thanks in advance, Andreas
Andreas Leitner writes: : | Given a lazy pure functional language do we need to differntiate | (in syntax) between constants and functions without agruments? And | if we don't need to, does Haskell make a difference? Haskell always treats a declaration of the form foo = ... as a pattern binding, not as a function binding. Sections 4.4.3 and 4.5 of the Haskell 98 report give more details. So, in that sense, every function in Haskell takes an argument. There's nothing to prevent you from adding a dummy parameter to turn a constant (i.e. a simple pattern binding) into a function. The only reason I've heard for doing so, is to work around the monomorphism restriction. HTH. Tom
Andreas Leitner wrote:
Hi,
I hope this is the right forum to post my question to.
Given a lazy pure functional language do we need to differntiate (in syntax) between constants and functions without agruments? And if we don't need to, does Haskell make a difference?
From a pedantic point of view your question makes no sense. The definition of a function is something that takes an argument and transforms it to a result. So a function always has exactly one argument. Period.
But from a practical point of view, yes you can regard constants as functions with no arguments. And it makes sense from a syntactic point of view: f0 = e0 f1 x = e1 f2 x y = e2 f3 x y z = e3 ... -- Lennart
participants (3)
-
Andreas Leitner -
Lennart Augustsson -
Tom Pledger