(Sorry, trolling. ML-style function call syntax would clash a lot with other parts of Python.)
(Sorry, trolling. ML-style function call syntax would clash a lot with other parts of Python.)
def g(): return 5
assert g() == 5
assert g != 5
Without parenthesis, how can the language distinguish the last two lines? How does ML do it? Would the same trick work in Python? I know Ruby has optional parenthesis, but functions aren't quite as first class there as they are in Python, which is why the have Proc and whatnot.Look here: http://try.ocamlpro.com/
Try this code:
let g() = 5 g() == 5 g != 5
First line defines the function. Second line should evaluate to true. Third line doesn't type check because a function is not the same type as a literal.
Haskell does differentiate between IO-actions and functions. Here is an example:
main = do
let printFive = print 5
print 1
printFive
print 6
printFive
Will print 1
5
6
5
The type systems helps enormously keeping things straight here, but the basic concept would work in a non-statically typed language, too.How? How do I compare. say, two functions for equality, without comparing the return value instead?
The decoupling of function calling and IO actions can work in non-statically typed languages, too.
Your question concerns a different topic. To give something like an answer: that problem can only occur with `functions' of zero arguments. Haskell sidesteps the issue by requiring all functions to have exactly one argument.