This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let (>=>) f g | |
= fun x -> (f x) >>= g;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let Join mm | |
= mm >>= fun x -> x;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec Sequence l | |
= match l with | |
| [] -> Return [] | |
| h::t -> h >>= fun h1 -> (Sequence t) >>= fun t1 -> Return (h1::t1);; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let ReturnList x = [x] | |
let FailList = [] | |
let (>>=*) m f = List.concat (List.map f m);; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let ReturnOption x = Some x | |
let FailOption = None | |
let (>>=?) m f = Option.bind f m;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type 'a io = IO of (unit -> 'a) | |
exception IOFailure | |
let RunIO (IO f) = f();; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let ReturnIO x = IO (fun () -> x) | |
let FailIO = IO (fun () -> raise IOFailure) | |
let (>>=) m f = IO (fun () -> RunIO(f(RunIO m)));; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let GetC = IO (fun () -> System.Console.ReadKey(true).KeyChar) | |
let PutC (c:char) = IO (fun () -> System.Console.Write c) ;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let EchoC = GetC >>= PutC;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let GetS length = | |
let rec get chars count = | |
if count > 0 | |
then GetC >>= fun c -> get (chars@[c]) (count – 1) | |
else Return IO String(List.toArray chars) | |
get [] length;; |