Here we have a function definition:
let f x = x + 3;;
Here is an expression:
let g = 4;;
Could g
just be thought of as constant function that takes no arguments? Is there any difference?
Yes - From a totally functional point of view (like practised in Haskell), everything is a function (Really everything).
And since a purely-functional language disallows any kind of change, this definition does not bear any contradictions.
Is there any difference?
Well, OCaml is not purely-functional. This means the functions are allowed to perform side-effects which differs a bit from the definition of a constant value.
This code (F# here - but quite similar in Caml) would be perfectly valid.
let name =
Console.Write("Enter your Name: ")
Console.ReadLine()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With