3 ms·
You might include something more explicit about function composition (e.g. the power of currying). Closures might be another thing to mention. For instance, yo
by unignorant 17y ago
You might include something more explicit about function composition (e.g. the power of currying).
Closures might be another thing to mention. For instance, you could show how they can be used to implement objects (which should be familiar to C# people).
- eru 17y agoComposability in general is a major attraction of functional languages. Haskell has an especially strong focus on it.
- DanielBMarkham 17y agoI'm torn on closures and currying/composition. Great concepts, sure. But in an hour? Might be too much to get their heads around. One of my code samples is going to be lifted from this great blog entry: http://diditwith.net/2008/03/14/WhyILoveFARefactoringTale.aspx http://diditwith.net/2008/03/14/WhyILoveFARefactoringTale.as... where he basically covers some of these concepts by way of example. I think no matter how I do it, it's going to look (to them) like some hand-waving and magic. Can't really help that, I don't think.
- evgen 17y agoIf you are going to go any distance into the functions as first-class citizens path then it might not be too much of a diversion to show a function that generates functions and then bounce quickly to simple currying as a more advanced example of this. You would not even need to describe it as currying..
- loup-vaillant 17y agoPlus, first class functions can be shown with mere high school mathematics. Lambda are really easy: the f: R -> R x |-> blah(x) you find in high school would be f : (float -> float) = fun x -> blah x In Ocaml (and probably F#). The composition operator can easily be seen as a function with two arguments, which show "first class" functions: o : (R->R), (R->R) -> (R -> R ) (f , g ) |-> (x |-> f(g(x))) And poof, you can introduce currying: o : ((R->R), (R->R) , R) -> R (f , g , x) |-> f(g(x)))