We talked about this a while ago, but I couldn't find the discussion.
Right now, the cleanest way to do monads is to use a type function:

/////////////////////////////////////////////////////////
#import <flx.flxh>

typedef fun Maybe (t:TYPE): TYPE => opt[t];

instance Monad[the Maybe] {
  fun ret[a] (x:a): opt[a] => Some x;

  fun bind[a, b] (o:opt[a], f:a -> opt[b]): opt[b] =>
    match o with
    | None[a] => None[b]
    | Some ?x => f x
    endmatch
  ;
}
open Monad[the Maybe];
/////////////////////////////////////////////////////////

(In fact, I can't figure out how to write this without using "the
Maybe". Maybe there's a bug?)

Since we only have one namespace for things, the standard library will
just have to reserve even more words to get things like this to work.
This would be much simpler if we could just treat unions as a type
function. It could also help to reduce some of the line noise in
definitions.

/////////////////////////////////////////////////////////
#import <flx.flxh>

instance Monad[the opt] {
  fun ret[a] (x:a): opt a => Some x;

  fun bind[a, b] (o:opt a, f:a -> opt b): opt b =>
    match o with
    | None[a] => None[b]
    | Some ?x => f x
    endmatch
  ;
}
open Monad[the opt];
/////////////////////////////////////////////////////////

Assuming we keep the opt[a] syntax, this shouldn't break any code.
Would it be complicated to implement?

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to