Skottish
unread,May 9, 2015, 8:42:18 PM5/9/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pdx...@googlegroups.com
Hi all,
As discussed a bit at the last meeting, I'd like to propose a talk for
this Monday demonstrating three tiny programs in three separate
languages: Haskell, Clojure, and OCaml.
For this first program, consider the following mathematical problem:
"[0..11] equals 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11. There is a single
one in 1, plus a single one in 10, plus two in 11, so there are four
ones total when incrementing from zero up to 11. Find all occurrences
over the set of non-negative integers where all of the accumulated ones
from zero up to a number equals that number."
The Haskell and OCaml versions of this program can complete the problem
in ~5/1000 of a second. After the JVM gets it's sip of coffee, the
Clojure version completes almost instantly as well. I have an informal
proof of when no more answers are possible, as well as an explanation
of the math behind how all of this works.
The second program (which I'll explain in person) started off life when
I was first learning Haskell. I decided to tackle some random problems
and found one in a forum. At that time the fastest implementation was
written in C and took 10.1 second to complete over a test data set. My
first attempt took ~35 seconds using only higher order functions. Using
the same algorithm and implementing what I learned as I went along,
it's now at 5.6 seconds over the same data set. There are useful
lessons in this version for Haskell learners about fast file processing
and drawing to screen. It also gives some insight into just how amazing
of a job that the GHC devs have done with their compiler.
The same program in Clojure is currently running at ~3x the speed of
the Haskell using the same algorithm. This one has had many surprises
about Clojure and would really enjoy if any Clojure hackers came along
to share some insight.
The OCaml version is lazy throughout (BatEnum); mainly because I
couldn't see any other way to do it in the few days that I spent
learning the language. It's currently the slowest of the three -- a
situation that I may try to attempt to fix before Monday. As with
Clojure, if any OCaml hackers would like to show up, insight would be
appreciated.
The last program is a command line weather program that gives complete
current weather from in some cases weather stations in the local
neighborhood. It contains a detailed seven day forecast for both day and
night. As well, it dynamically allocates space for weather alerts. All
of this uses the JSON API from Weather Underground.
The Haskell version features Aeson including the ability to deal with
JSON that can and does regularly changes types. It uses quite a bit of
the capabilities of Data.Text.Lazy for comprehensive string-like
functions. It also features Data.Text.Format for type safe printf like
output.
The Clojure version features the 'json' library and like many things
Clojure, everything else is 'batteries included'. Also not too
surprisingly, it uses less code than the other two.
The OCaml version features Yojson. I ran into some issues with dealing
with UTF8 and not finding libraries that I was looking for, so it also
features me working around things... probably unnecessarily.
If anyone is up to this talk, I'd be glad to do it. If I do, I very much
welcome other's insight into simpler code that performs to a language's
capabilities.