On 9/25/07, Erick Tryzelaar <[EMAIL PROTECTED]> wrote:
> Isn't this kind of monadic? Do I understand monads enough that you
> could define a combinator to do this?
>
> File::open 'foo' >>= File::getlines >>= List::sort >>=
> List::iter[string] (fun (line:string) =>
> println line;
> );
>
> -e
If we used something similar to haskell's error and list monads, we
could have something like this (culling the typeclasses):
union failure[a,b] =
| Failure of a
| Ok of b
;
fun openf (f:string): failure[string,List::list[string]] =
{
return Ok[string,string] List::list("a","b","c");
}
fun lift[A,B,C] (f:B->C) (x:failure[a,b]): failure[A,C] =>
match x with
| Failure ?x => Failure[A,C] x
| Ok ?x => f x
endmatch
;
match
openf "foo" >>= lift $ the List::sort >>= List::iter (fun (line:string) =>
print $ (repr line) + " ")
with
| Failure ?e => { println $ "failed with: " + e; }
| _ => {}
endmatch;
I think this could work, and while normally I can't really "read" what
>>= means in haskell, here I kind of understand how things are being
piped around.
With catch from haskell, this could be done like this:
catch
(openf "foo" >>= lift $ the List::sort >>= List::iter (fun (line:string) =>
print $ (repr line) + " "))
(fun (e:string) = { println $ "failed with: " + e; });
-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language