CSC302 2011S, Class 23: Haskell (2) Overview: * Haskell v. Clojure. * The Second Haskell Lab. Admin: * Missing (unexcused): JQ * Missing (excused): AC, DG, CF3, CF4 * Pop Tarts! * There is a lot of illness going around campus. Please try to take care of yourselves. * Because so many of you seem so ill, and could probably use the extra rest, there will be no class on Friday. I still expect questions on the last Haskell section. * We'll do Monads and arrows and similar junk after break * Mid-semester exam to be distributed tomorrow. Due Saturday after break. * A few of you reported on Piazzza being insanely slow at times. I talked to the Piazzza people at the conference, and they asked that you send them email when you encounter slowness. Why learn Haskell if you already know Clojure? * Purity - A different approach; we're used to side effects * We tend to compromise on purity, even when we know that it's useful * Purity helps keep programs provably correct and reliable * Force us to think differently * Parallel programming is much easier in a pure environment * We can believe that the compiler takes advantage of it * Side effects in a pure language is a huge stretch. Let's make our brains hurt some more with monads * Syntactic sugar - It's good for us to see multiple syntaxes for the same sweet concept. * Currying is different (much simpler than l-s and r-s) * We needed another really confusing language * Strong, Static Typing with Type Inference * Much better than in any language we've studied * Rare bugs * Tail recursion is optimized Why learn Clojure if you're going to learn Haskell? * Combine different paradigms and learn how they can be productively mixed. * Clojure is on the JVM and the CLR and therefore can access large libraries * (Not in Tate, but a reason to learn Clojure.) * Baby steps * The data == code idea * Perhaps we should show this more * Macros Lab! digitToInt x = (fromEnum x) - (fromEnum '0') or digitToInt '0' = 0 digitToInt '1' = 1 digitToInt '2' = 2 digitToInt '3' = 3 digitToInt '4' = 4 digitToInt '5' = 5 digitToInt '6' = 6 digitToInt '7' = 7 digitToInt '8' = 8 digitToInt '9' = 9 --- atoi str = foldl (\x y -> 10*x + y) 0 (map digitToInt str) or atoi = (foldl (\x y -> 10*x + y) 0) . (map digitToInt)