What is Functional Programming? Part 5, Bindings
Join the DZone community and get the full member experience.Join For Free
n.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.
update: this next part is not technically accurate and i do not mean to imply that it is. rather, this is how my poetic eye has begun to see the code.
after this clicked with me, i also to 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 (for me). it is the marriage of value and function .
next stop, pattern matching in f#.
Opinions expressed by DZone contributors are their own.