top | item 38353288

(no title)

johnday | 2 years ago

The value of purely functional programming languages, as opposed to functional programming languages like lisps, is that you get referential transparency, which means that when you define `a = b`, you know that you can always replace any instance of `a` with `b` and get the same answer. This is a very natural property in mathematics (algebraic rewritings are basically just this property writ large) and so it helps to draw nice parallels between the familiar notation of functions from mathematics and the "new" and "confusing" notion of functions in functional programming and other declarative languages.

As other posters have said, strong typing is also a nice property for lots of reasons, most notably it gives a platform to talk about ad-hoc and parametric polymorphism.

(I lecture on Functional Programming at the University of Warwick, where we use Haskell.)

discuss

order

tmvphil|2 years ago

I think SML isn't purely functional (although it naturally encourages a purely functional style).

tonyg|2 years ago

The first problem with this argument is that referential transparency is a property of syntactic positions, not of languages.

The second is that languages like Lisp, SML, C, Pascal and BASIC all have referentially transparent and referentially opaque positions in exactly the same way that languages like Haskell do.

This means that all these languages enjoy referential transparency in the same way, because when you unpack the notion of equivalence, referential transparency itself is within a whisker of being a tautology: if a is equivalent to b, then you can substitute a for b or b for a. The relevant sense for "is equivalent to" can really only be contextual equivalence, which is all about meaning-preserving substitutability.

That said, not having to reason about effects within one's program equivalence sure makes things simpler in a pedagogical setting. But that's not to do with referential transparency per se.

albedoa|2 years ago

For those of us who are unfamiliar with Lisps, can you expand on how they break referential transparency (and how Standard ML contrasts in that regard)?

epgui|2 years ago

They don’t.

Or at least not inherently, if by “lisp” one is primarily referring to s-expressions.

medo-bear|2 years ago

He is probably talking about namespaces. In common lisp, for example,

   (a a)
calls a function 'a' on a variable 'a'. Lisp knows this because the first thing that comes after the left paren is a function