views:

505

answers:

4

Hi guys,

According to you, which language do you think would be the best for implementing monads (Python/Ruby/LISP)?,also can anyone tell me some possible uses of monads (please give examples),like exceptions?

Thanks in advance

+1  A: 

For examples, see Philip Wadler, "Monads for functional programming".

Craig Stuntz
+7  A: 

In order of preference:

  1. Haskell
  2. F#
  3. Scala
  4. C#

Monads in order of decreasing simplicity:

  1. Maybe (Exception)
  2. Reader
  3. Writer
  4. State
  5. Parser
  6. Async
gandjustas
No OCaml or is that listed with F#?
wheaties
Ocaml have no builtin syntactic sugar for monad unfortunately
gandjustas
Scala > F#. Why? Simple. In Scala you can write functions operating on any monad, which you can't in F#, because that requires higher-kinded types.
Alexey Romanov
Because i know f# better :) But in f# i can write some functions operating on any monad with compile-time type resolution.
gandjustas
Good list, but I would also put Scala above F#. I'd also add List and Set between Maybe and Reader, and Continuation between Parser and Async.
Dave Griffith
Async - is continuation monad. List usualy already implemented in all languages supporting monads. I just frogot him.
gandjustas
Scala belongs higher than F# regarding "language ... best for implementing monads ". Scala has higher-order polymorphism, allowing the expression of the monad abstraction. F# does not, disallowing it.
Tony Morris
You forgot the simplest monad of all: Identity!
pelotom
+19  A: 

All About Monads - legendary tutorial that lists all the standard monads and gives a lot of real-world examples.

Popular monads that you can meet even in the mainstream languages are Maybe, List and Continuation. Some people also think that jQuery itself is a monad (as it follows the monadic axioms).

As for the language choice, Haskell and its derivatives are using monads as a fundamental concept, however, as an option, constructing monads is possible in a lot of modern languages. In order to familiarize with the monad concept I'd better choose the language I'm the most comfortable with.

Vasil Remeniuk
Awesome tutorial!
Ishihara
+3  A: 

Here are some tutorial that use clojure. Monads are implemented in a library.

nickik
although monads are not idiomatic in clojure (in most cases there is a alt way to get the same objective with other langs features), and its official implmentation has a lot of macro hackery, it's possible to use them. I would add another tutorials: http://intensivesystems.net/tutorials/monads_101.html , http://erl.nfshost.com/2010/09/05/bind-unit-and-all-that-2 and http://onclojure.com/2009/06/24/protecting-mutable-state-in-the-state-monad/
jneira