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.
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.