But assuming you do manage to compile and install Oleg's library, here's how you'd use it in an OCaml session:
#require "delimcc";; (* loading Oleg's library this way requires the findlib package *)
+ (* if you don't have findlib, you'll need to start ocaml like
+ * this instead: ocaml -I /path/to/directory/containing/delimcc delimcc.cma
+ *)
open Delimcc;; (* this lets you say e.g. new_prompt instead of Delimcc.new_prompt *)
let p = new_prompt ();;
let prompt thunk = push_prompt p thunk;;
* All About Monads has supposedly also been integrated into the Haskell wikibook
* (A not-so-)[Gentle Introduction to Haskell](http://web.archive.org/web/http://www.haskell.org/tutorial/) (archived)
* [Learn You a Haskell for Great Good](http://learnyouahaskell.com/)
-
+* [Another page comparing Haskell and OCaml](http://blog.ezyang.com/2010/10/ocaml-for-haskellers/)
##Type expressions##
##Records##
-Haskell and OCaml both have `records`, which are essentially just tuples with a pretty interface. The syntax for declaring and using these is a little bit different in the two languages.
+Haskell and OCaml both have `records`, which are essentially just tuples with a pretty interface. We introduced these in the wiki notes [here](/coroutines_and_aborts/).
+
+The syntax for declaring and using these is a little bit different in the two languages.
* In Haskell one says:
In OCaml:
- let { red = r; green = g } = c
+ let { red = r; green = g; _ } = c
in r
In Haskell:
In OCaml it's:
- # let makegray ({red = r} as c) = { c with green=r; blue=r };;
+ # let makegray ({ red = r; _ } as c) = { c with green=r; blue=r };;
val makegray : color -> color = <fun>
# makegray { red = 0; green = 127; blue = 255 };;
- : color = {red = 0; green = 0; blue = 0}
+* Records just give your types a pretty interface; they're entirely dispensable. Instead of:
+
+ type color = { red : int; green : int; blue : int };;
+ let c = { red = 0; green = 127; blue = 255 };;
+ let r = c.red;;
+
+ You could instead just use a more familiar data constructor:
+
+ type color = Color of (int * int * int);;
+ let c = Color (0, 127, 255);;
+
+ and then extract the field you want using pattern-matching:
+
+ let Color (r, _, _) = c;;
+ (* or *)
+ match c with Color (r, _, _) -> ...
+
+ (Or you could just use bare tuples, without the `Color` data constructor.)
+
+ The record syntax only exists because programmers sometimes find it more convenient to say:
+
+ ... c.red ...
+
+ than to reach for those pattern-matching constructions.
+
+
##Functions##
For more details, see:
* [Haskell wikibook on do-notation](http://en.wikibooks.org/wiki/Haskell/do_Notation)
+ * [Yet Another Haskell Tutorial on do-notation](http://en.wikibooks.org/wiki/Haskell/YAHT/Monads#Do_Notation)
* [Do-notation considered harmful](http://www.haskell.org/haskellwiki/Do_notation_considered_harmful)
* If you like the Haskell do-notation, there's [a library](http://www.cas.mcmaster.ca/~carette/pa_monad/) you can compile and install to let you use something similar in OCaml.