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 ( ^* ) (generator: ('x option -> continuation) -> continuation, test) | |
| (consumer: 'x list -> 'x option -> continuation) = | |
| generator (function Some x -> if test x | |
| then (generator, test) ^* (fun l -> consumer(x::l)) | |
| else consumer [] (Some x) | |
| | None -> consumer [] None);; |
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 LispLex = Bra | Ket | Dot | Str of string | Num of int | Symbol of string | |
| let alpha c = ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) | |
| let digit c = (c >= '0') && (c <= '9') | |
| let eqChar c c' = c = c' | |
| let l2s l = String(List.toArray l) | |
| let ( ^| ) p q = fun x -> (p x) || (q x) | |
| // Read a symbol from the input | |
| let readSymbol s char g = | |
| (lexGetChar s, alpha ^| digit ^| eqChar '_') ^* |
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 continuation = K of (unit -> unit) | |
| step1: continuation -> continuation | |
| end: continuation | |
| program = step1 end : continuation |
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
| Return: t -> M t | |
| Fail: M t | |
| Bind: (t1 -> M t2) -> M t1 -> M t2 |
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
| m >>= fun value1 -> | |
| E1[value1] >>= fun value2 -> | |
| E2[value2] |
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
| value1 := m; | |
| value2 := E1[value1] | |
| E2[value2] |
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 __binder__<'T, 'U, 'M when 'M : (static member bind : ('T -> 'U 'M ) -> 'T 'M -> 'U 'M)> (x: 'T 'M) (f : 'T -> 'U 'M) = | |
| x |> 'M.bind f;; | |
| let (>>=) = __binder__;; |
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 (>>) m1 m2 = m1 >>= fun () -> m2;; |
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 Apply m1 m2 | |
| = m1 >>= fun f -> | |
| m2 >>= fun x -> | |
| Return (f 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 Lift f m = | |
| m >>= fun x -> | |
| Return (f x);; |