What is Functional Programming? Part 5, Bindings
Join the DZone community and get the full member experience.
Join For FreeN.B. this is unrelated to the concept of bindings in Silverlight and WPF.
One of my aha moments in learning F# occurred while I was reading Real World Functional Programming. Specifically, it was when the meaning of the let keyword really clicked. Before I explain, here are couple of samples:
let x = 42 let multiply a b = a * b
I was predisposed to interpret let as merely declaring a variable. but you will recall from the first post that we made a distinction between working with mutable “variables” and immutable “values”. Functional languages eschew mutability.
If you look up let in the official documentation and you’ll see that it is called a binding and it is very clearly described:
A binding associates an identifier with a value or function. You use the let keyword to bind a name to a value or function.
This also aligns with the concept of referential transparency we mentioned way back in the first post.
This may seem obvious or even a subtle distinction to make, but I think it is fundamental in understanding the functional approach.
After this clicked with me, I also realized that I can think of
let x = 42
as a function with no arguments that returns a value of 42. The distinction between binding to a value and binding to a function blurs. It is the Marriage of Value and Function.
Next stop, pattern matching in F#.
Published at DZone with permission of Christopher Bennage, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments