Uses of Haskell

Download Report

Transcript Uses of Haskell

Haskell
Chapter 1, Part I
Why are we doing this?

http://stackoverflow.com/questions/3175656/why-shouldi-want-to-learn-haskell

http://programmers.stackexchange.com/questions/25569/i
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


http://www.defmacro.org/ramblings/fp.html
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.
http://www.defmacro.org/ramblings/fp.html
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.
http://www.reddit.com/r/haskell/comments/10nast/is_haskell_a_good_language_to_develop_artificial/
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…
http://stackoverflow.com/questions/397425/when-to-use-a-functional-programming-language
Haskell







http://www.haskell.org/haskellwiki/Haskell_Communities_
and_Activities_Report
Pretty print -> parser
Parse epub3 metadata
Auto-completion
DSL for generating JavaScript (Sunroof)
Computation (automatic differentiation, numeric
integration, bifunctors, etc.)
Chordify – extract chords from music sources
Real-world FP - F#






http://homepages.inf.ed.ac.uk/wadler/realworld/
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