|Do you know where your variables are?|
Re: RFC: A Perlesque Introduction to Haskell, Part One (draft)by blokhead (Monsignor)
|on Jun 23, 2004 at 21:58 UTC||Need Help??|
Disclaimer: I haven't had any experience with Haskell, only OCaml, which is similar in many respects (type-inferencing and good pattern matching).. my Haskell syntax might be off at times, so bear with.
What you call extensionality is what I've known as currying. And a description of it will probably be easier if you talk more about type signatures and type inferencing.
In my opinion, the absolute coolest features of modern function languages (other than just being functional) are type inferencing and pattern matching. They are foreign concepts if your only programming background is Perl (especially type inferencing), so you should give them both a bit more time. Other cool features that you do mention are polymorphic types (Num a), and lazy evaluation of infinite objects (which I've never had any experience with).
As for pattern-matching, the absolute coolest demonstration of this is quicksort in 2 or 3 lines of Haskell (Update: code here). It shows how elegant and powerful pattern-matching can be... especially in Haskell, which has the most expressive matching out there.
WRT currying, it's easy to grasp by having a good understanding of what the type signatures mean -- plus it gives you a bit of insight into the language internals as well. The type signatures for multi-arg functions look like this:
Note that there are no parens in the signature a -> a -> a. This is a function of two variables, so why isn't the signature something like (a, a) -> a ?? Turns out that arrow is right-associative, so the type signature really means:
When you read it this way, you can see that sum is a function of one variable that returns another function of one variable. Under this view (the lambda-calculus view), currying is simply a natural side-effect:
sum 1 returned a function of one variable (a -> a), just like the type signature said it would! It's also important to notice that at this point, the type-inferencing engine may have specified the polymorphic type a to an Int type (don't know Haskell well enough to say for sure).
Function application on multiple arguments also makes sense under this interpretation as a left-associative operation:
Multiple arguments and currying just come naturally by looking at functions from a lambda calculus context.
Also, MJD has a Perl-based talk about Strong typing that uses ML and gives a good example about how type inferencing helps the programmer catch bugs (I can attest to that).
Anyway, you're making me want to write an OCaml primer (and learn Haskell) ;) Good work so far!