#1004 Monads in Fantom

KevinKelley Thu 4 Mar 2010

Somebody a while back mentioned a clojure link, and I got interested and subsequently tripped over their monads implementation, which led to some Haskell links, and papers by Wadler, and by Hutton and Meijer...

Anyhow I got interested in trying to implement monads in Fantom; it turned out to be interesting enough that I went ahead wrote it up.

My wiki pages start at http://www.kelleysoft.com/wiki/Monads, and the matching source is on github at http://github.com/KevinKelley/fantom-monads.

Monads are a thing that seems to be considered fundamental, to Haskell types; important, to the Lisp world; and hardly on the radar, to Java people. There's probably a lot of reasons for that, some of them good; one reason though is just lack of familiarity with the implementation platforms: it's hard to make sense of an explanation, if the example's in Haskell and you don't know Haskell.

So anyway, it seemed like a good idea to first, bring the examples into my world. Then, play. I'll welcome any feedback and appropriate derision. :-)

msl Fri 5 Mar 2010

My head hurts...

I think that's a good thing! Great info!! :)

tactics Fri 5 Mar 2010

Although moands have no place anywhere outside of Haskell, the Redditors will eat this up :)

KevinKelley Fri 5 Mar 2010

Heh. Part of my motivation in all that was to try to decide for myself whether monads are just a tool for the theoreticians, or whether they're potentially a useful "regular programmer" thing. I think it's pretty clear that it's not something you'd do every day. Nobody's that much of a masochist. :-)

There's some pretty interesting stuff in there, though. And, I think, important, maybe not so much for day-to-day kinds of things, but as a way of thinking about the fundamentals.

Anyway I'm having a lot of fun with the subject. And if I can share the headaches it gave me, all to the good.

tactics Fri 5 Mar 2010

I was really into Haskell for a while. The language is really cool and has some really amazing ideas, Monads included. And the community was the friendliest community I've ever been a part of*.

However, I fell out of it, because a lot of it is theoretical nonsense. The language was created for computer science professors wanted an open non-strict programming language so they could collaborate. It's also a kitchen sink language and remarkably Perl-ish ;)

Monads are very awesome, even though the raw mathematical concept is too abstract to be useful. However, they excel at many traditionally difficult tasks:

  • containers (Maybe, List, trees)
  • state (IO, StateT, Random, Reader, Writer, subsets of IO via transformers)
  • parsers
  • STM

There are lots of great things coming out of the language. It's still very young. I hope some day someone comes up with another non-strict language that takes all the good from Haskell and leaves the unproven stuff behind.

Sadly, though. Not much of it is helpful to Fantom. Haskell is all about strict typing. Fantom isn't. Every novel concept in Haskell is based around the type system, and Fantom can't leverage that.

* Seriously, hang out at #haskell IRC for a few weeks. I think Fantom and every other language has a lot to learn from them. They are the most welcoming and helpful group of people.

brian Fri 5 Mar 2010

Kevin - this is a great treatment of monads. It is refreshing to see info on monads in a language other than Haskell (Fantom being a good choice!). Although it definitely illustrates how much verbose a language like Fantom is for hard-core functional programming. Haskell is beautiful in that regard.

LINQ incorporates a lot of the monad ideas in a way practical to normal programmers. That has been a lot of the inspiration behind what we are doing with SkyFoundry's data analysis technology.

Hope to see it on Proggit :-)

tactics Fri 5 Mar 2010

Don't forget to link it when you post it so we can all upvote it ;)

KevinKelley Fri 5 Mar 2010

I added a link to it, on reddit, "A survey of Monads, in Fantom language"...

tactics Fri 5 Mar 2010

Nice.

I noticed you didn't list Software Transactional Memory on your page. If you don't already know about it, I highly recommend you read Simon's article Beautiful Concurrency.

In my eyes, this is the most innovative use of Haskell. From the standpoint of the API, it is the absolute perfect solution to concurrency. There's still need for improvement on techniques for its underlying implementation, but for smaller concurrent applications, it's shared-state concurrency that "just works".

KevinKelley Fri 5 Mar 2010

There's too much! Everything's linked to everything, and I can't follow it all!

That's a good paper, I read it in "Beautiful Code" a while back. STM sounds nice, but I've not wrapped my head around how it's going to get implemented. Though apparently clojure's managed it.

Wadler has a chapter applying monads to array (memory) updates, which is interesting, theoretically.

Here's something that should interest you, if you haven't seen it... using immutable objects is good for concurrency; but, making const copies of big structures whenever you change something, is inefficient. But! Haskell to the rescue! Turns out you can make a change to a const structure by sharing the unchanged parts. A recent post in the clojure list references this: Priority Queue -- this is a java implementation; that link has a couple of good papers about it.

Login or Signup to reply.