Monads and Maybe

Konrad Hinsen hinsen@cnrs-orleans.fr
Tue, 19 Aug 2003 12:42:37 +0200


I have been following the recent "Monad tutorial" discussion with interes=
t,=20
and even read the tutorial, which is a useful addition to the existing=20
Haskell documentation. So useful in fact that it raises a question...

The whole monad mechanism seems to geared towards functions of one argume=
nt,=20
plus eventually state, that get chained together. How about functions wit=
h=20
several arguments?

As an example, I'll use the Maybe monad. Suppose I want to write code to=20
handle experimental data, in which there might be missing values. I might=
=20
then decide to represent measurements by data of type "Maybe Double", wit=
h=20
missing values represented by "Nothing". I could then go on to define=20
functions on missing values, which would return "Nothing" when their argu=
ment=20
is "Nothing", and I could string these functions together via the monad=20
mechanism. Fine.  But how would I handle e.g. addition of two such values=
?=20
The result should be "Nothing" when either of its arguments is "Nothing".=
 Is=20
there any mechanism to handle that?

Konrad.