Presentation on theme: "Haskell Chapter 1, Part I. Why are we doing this? i-want-to-learn-haskell"— Presentation transcript:
Haskell Chapter 1, Part I
Why are we doing this? i-want-to-learn-haskell i-want-to-learn-haskell s-haskell-worth-learning s-haskell-worth-learning
Why study functional languages? Without understanding functional programming, you can’t invent MapReduce, the algorithm that makes Google so massively scalable. —Joel Spolsky, The Perils of Java Schools
Perspective This is where the story would stop, I'd wrap up the article, and you'd navigate to another page, if not for the beginning of World War II. The world was in flames. The U.S. Army and Navy used artillery more often than ever. In attempts to improve accuracy the Army employed a large group of mathematicians to continuously calculate differential equations required for solving ballistic firing tables. It was becoming obvious that the task was too great for being solved manually and various equipment was developed in order to overcome this problem.
Theory of Computation Independently of Alonzo Church, Alan Turing was performing similar work. He developed a different formalism (now referred to as the Turing machine), and used it to independently come to similar conclusions as Alonzo. Later it was shown that Turing machines and lambda calculus were equivalent in power.
Why FP? In general, use the language in which it's easiest to express the solution to a problem. For functional programming, this is when the solution to a problem is easily expressed in terms of functions, hence the name. Generally it's good for mathematical operations, AI, pattern matching; in general anything that can be broken down into a set of rules that must be applied to get an answer. You can only really determine the "best" language to use after you've analyzed your problem sufficiently. This is where pseudo-code comes in handy. If you find yourself writing pseudo-code that looks like FP, use FP.
AI I started working through the book Artificial Intelligence: A Modern Approach by Russell and Norvig and implementing the algorithms in Haskell. You can see the code … but it's a demonstration that you can write AI code in Haskell without much trouble. Some things I learned in the course of doing this: Haskell is excellent at creating domain specific languages, which made writing the logical reasoning modules (propositional and first order logic solvers) very easy. Compare it to the 'official' implementation in Python and you'll see that the Haskell version is much more understandable. The fact that probability distributions form a monad greatly simplify any code that has to deal with probabilistic effects. Being able to separate pure actions from I/O is a huge boon. It enabled me to write algorithms like graph search, alpha/beta search and constraint propagation without thinking about how the user would have to interact with them, and only later add in the I/O routines.
Pattern Matching Domain specific languages Compilers Data transformations Today, pattern matching is found in almost all functional languages including OCaml, F#, Scala, Haskell, Clojure and Erlang. For example, I recently built a bespoke business rules engine for a client with a focus on mathematics. That is 1,000 lines of F# and is predominantly an interpreter. Lexing, parsing, type checking and interpreting input are all much easier thanks to pattern matching. Lexing IS pattern matching…
Real-world FP - F# Using F# to develop quantitative models for financial products Grange Insurance parallelized its rating engine to take better advantage of multicore server hardware For a machine learning scientist, speed of experimentation is the critical factor to optimize. We see great potential for F# to be used as a scripting language in CAD; it fits very well for computational design challenges in the construction industry. F# encourages Reason Driven Development that leads to virtually bug-free code (Fixed Income securities trading optimization.)
More real-world FP (not just F#) Syntax Tools Theorem Provers and Reasoning Assistants Network Toolkits and Applications (e.g., Gopher, FTP) Natural Language Processing and Speech Recognition Web, HTML, XML Database Systems Games and Novelties