On 1/5/2012 9:26 PM, Toby Thain wrote:
On 05/01/12 12:09 PM, Liam Proven wrote:
...
For instance, the lambda calculus. What is it? What does it do, what
is it for, why is it special?
There is a wealth of material at all levels devoted to this. Pick up any
functional programming text, e.g. I highly recommend
* Functional Programming - Application and Implementation (Henderson).
* The Architecture of Symbolic Computers - Peter M. Kogge
* Types and Programming Languages by Pierce
This book explains type theory and the theory of programming languages.
You write several little interpreters, like an interpreter for the core,
untyped lambda calculus. You learn about the relevance of lambda
calculus as a fundamental computer science concept, and how one builds
upon that. As said, it explains type theory too.
* Purely Functional Data Structure by Okasaki
Talks about data structures which are immutable and efficient, suitable
for purely functional languages. This is more about functional
programming than the lambda calculus.
* Introduction to Functional Programming using Haskell by Bird
This is a book, *not* about Haskell, but rather about functional
programming. That is, it's relatively language unspecific, but uses
Haskell as a vehicle for examples.
* Learn You A Haskell For Great Good by Lipovaca
Okay, now if you want to be spoonfed Haskell and functional programming,
read this. You'll start with syntax, recursion, and types; and it'll
carry you to monads, zippers, applicative functors, randomness, etc.
It does not talk about really serious stuff like unsafe IO, some of the
finer points of lazy evaluation, monad transformers
Closures: again, I have yet to find a readable, comprehensible
explanation of what they are, what they are good for, why they are
powerful and what strengths they confer onto a programming language.
Readable and comprehensible explanations:
* SICP
* Programming in Scheme (Abelson & Eisenberg)
* aforementioned Henderson.
and dozens of others. There are A LOT of good functional programming
texts out there, many dating back to the 70s and 80s of course, and far
in conceptual advance of the mainstream (PHP!
ASP.NET! Java! snore).
SICP should explain closures just fine. I mean, not only are closures
(and lexical scope as a prerequisite) explained, but you also use
closures in a practical way. And there is no way SICP is poor.
* Let Over Lambda by Hoyte
Chapter 1 of this book dives into a pragmatic explanation of what a
closure is by describing it as a "Let Over Lambda". For example
(define closure
(let ((x 2))
(lambda () (display x)))
This is an extremely simple example. CLOSURE is bound to a lambda
expression. But not just some pure lambda, it has extra information
about its environment. So it's a lambda (code) + environment (data). If
we proceed to call CLOSURE, we get:
(closure)
2
We can be more fancy:
(define counter
(let ((count 0))
(lambda ()
(set! count (+ 1 count))
count)))
Here the lambda captures COUNT. Now we call COUNTER a few times:
(counter)
1
(counter)
2
(counter)
3
Look ma! Encapsulation! COUNT is not accessible from the outside. C++ers
might call this a ~private variable~, but really it's just a variable
closed inside some execution context.
Anyway, that's what Chapter 1 of said book talks about.
* Lisp In Small Pieces by Quiennec
This talks about compiling Lisp if you're interested in how closures
might be compiled. It also talks about formal semantics and other mathy
stuff.
>
> If the teaching& reference materials that I have found so far are
> unable to convey these core concepts, then there would seem to be two
> possible conclusions:
>
> [a] /all/ the materials that I've been able to find are extremely
> poor, even the ones that are more or less universally agreed to be
> very good
>
> or
>
> [b] these are complex, difficult concepts and a massive amount of
> back-knowledge is necessary to understand it.
No, these are not necessarily poor nor complex just because *you* don't
understand it.
>
> I would *REALLY* like and hugely value any pointers, ideally web links
> but print references would do as well, as to these concepts.
>
> But are there other possible explanations that I have missed? That
> these things are easy but all the texts are rubbish?
>
The best way to go about it is to actually write some programs in Scheme
or Standard ML or Haskell or whatever. Then you actually internalize
what things mean, instead of these abstract definitions like what the
semantics of lambda is. You'll find the easy-to-understand books
typically do the programming for you by showing you code examples.
Remember, programming isn't like history, where you can just read a book
and understand what's going on. It's more like medicine and being a
doctor, where both book reading *and* practice are important, the latter
being almost surely more important.
--Robert
P.S., The moral of the story is, sit down, open a Scheme, and read SICP
from start to finish. It's not too difficult or too
confusing, for it's
often the first book a compsci major gets to read.
READ SICP DAMMIT.