in reply to Re^11: World's shortest intro to function programming
in thread Thread on Joel on software forum : "I hate Perl programmers."
The real essence and subtlety of FP is the typing systemAh, ha. Now we're getting somewhere. I could definitely see where one could go astray, if they start following the reasearch guys too closely. They *love* proposing new additions to the type system to see what results (that's their job after all). Here's where I'll heartily recommend the book The Haskell School of Expression: Learning Functional Programming through Multimedia. I found I needed an actual text to use in my journey into FP. While PDF's might be good enough to learn a new language if it is sufficiently close to one I already knew, I found learning FP from PDF's to be mostly unworkable. "The School of Expression" book covers the Haskell-98 standard, which ignores the bleeding edge type system extensions (this is a good thing). Also, as a side note, I'm obligated to mention that while static typing might be used in the more popular FP languages like Haskell and OCaml, it is by no means the essence of FP. You can do FP in Scheme and Perl if you so desire (I'll also mention my new favorite untyped functional language,Joy, although it is pretty much completely impractical at the moment).
Uses syntax in the examples that you can't simply type into the "runloop interfaces" without modifying it.The Haskell interpreter prompt is inside an implicit "do" block (which is what sequences IO actions in a lazy language like Haskell). I could see where that could be confusing. What that basically means is that you have to use the 'let' keyword to introduce a new definition. (Not to be confused with "let .. in" construct you use in regular code).
What I mean by "2D syntax" the Python-style required whitespace--2d alignment rules.That's probably just one of those "matters-of-taste" things. Some folks like curley braces, others don't.
And what is 'a? Where did that come from? "a" seems to be a "generic type placeholder" generated by the type inferencing, but what is the ' doing? Is it a function that tests the value of the type represented by the "a"?I know nothing about Ocaml, but I'll take a stab at it anyway. In Haskell, there's nothing too special about the single quote, so you can use them as part of your variable names. When used that way, it is pronounced "prime". Also in Haskell, use of lower case names in a type signature indicate a type variable (the type signature shows what the types of the arguments and return value are for a function). A type variable can represent any type, as opposed to a specific type instance like Integer, Float, String, etc. (note the capitalization). For example, the type of "map" is...
...which means that "map" takes two arguments (ignore currying for now). The first argument (a -> b) is a function which takes elements of type "a" and returns elements of type "b". The second argument ([a]) that "map" takes is a list of elements of type "a". And the return type is a list of elements of type "b". For instance, if...map :: (a -> b) -> [a] -> [b]
...then "map strlen example" would evaluate to the list [3,3,6].strlen :: String -> Integer strlen x = length x example = ["dog", "cat", "orange"]
The Haskell tuts never explain what '$' does that I have found, but if you look at any non-trivial Haskell code, it pops up all over the place. (I know what it does now through trial and error!).Yup. That's a legitimate complaint. The '$' application function is under explained and mainly used to eliminate parenthesis.
And '.'. This is explained, usually as f . g x = f( g( x )) or f . g x = (f (g x ) ) depending upon flavour, but what that doesn't tell you is when you need to use it! In most dialecs, simple abutment of functions f g x achieves the same thing--except when it doesn't and the '.' is required!Yeah, function application precedence was a little tricky for me at first in Haskell (and curried everything doesn't make it easier), but you'll get the hang of it with a little practice.
Enough ranting, (sorry you caught me after another fruitless search for information and examples, and several long and ultimately useless downloads of PDFs that I had to search manually because the stupid UI won't let me search for stuff that wasn't bloody indexed. Grrr!).No problem! Ranting is par for the course when undertaking any new exercise. Hang in there, it'll get easier the more you do.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^13: World's shortest intro to function programming
by BrowserUk (Patriarch) on Jun 20, 2005 at 07:06 UTC | |
by kelan (Deacon) on Jun 21, 2005 at 19:45 UTC | |
by BrowserUk (Patriarch) on Jun 21, 2005 at 20:11 UTC | |
by Anonymous Monk on Jun 20, 2005 at 15:46 UTC | |
by BrowserUk (Patriarch) on Jun 20, 2005 at 19:38 UTC | |
by Anonymous Monk on Jun 20, 2005 at 20:07 UTC | |
by Anonymous Monk on Jun 20, 2005 at 20:49 UTC | |
by kelan (Deacon) on Jun 21, 2005 at 14:44 UTC | |
by BrowserUk (Patriarch) on Jun 21, 2005 at 20:17 UTC |