X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=translating_between_OCaml_Scheme_and_Haskell.mdwn;h=63b3263094081203bebf75fd062564599cff4082;hp=4b0f715432c96dff25a2eed522f92bb7adcc985a;hb=b3fcd749ac69521ca598d3846043bb7aff1ac290;hpb=7d1a4657f55750d3eb1571a498573cf0faada29c diff --git a/translating_between_OCaml_Scheme_and_Haskell.mdwn b/translating_between_OCaml_Scheme_and_Haskell.mdwn index 4b0f7154..63b32630 100644 --- a/translating_between_OCaml_Scheme_and_Haskell.mdwn +++ b/translating_between_OCaml_Scheme_and_Haskell.mdwn @@ -70,7 +70,7 @@ Additionally, the syntax of OCaml and SML is superficially much closer to Haskel Second, you can create real datatypes and pattern-match on them. There are several tools for doing this. I'll describe the `define-datatype` and `cases` forms developed for the book *Essentials of Programming Languages* (EoPL) by Friedman and Wand. - (Alternatives include the `struct` form in Racket, see . Also `define-record-type` from srfi-9 and srfi-57; see also .) + (Alternatives include [the `struct` form in Racket](http://docs.racket-lang.org/guide/define-struct.html). Also `define-record-type` from srfi-9 and srfi-57; see also [the r6rs libs](http://docs.racket-lang.org/r6rs-lib-std/r6rs-lib-Z-H-7.html).) Here is how the tools from EoPL work. You must begin your file either with `#lang eopl` or with the first two lines below: @@ -91,7 +91,7 @@ Additionally, the syntax of OCaml and SML is superficially much closer to Haskel (free-vars (lam 'x (app (var 'x) (var 'y)))) ; evaluates to '(y) -* Scheme has excellent support for working with implicit or "first-class" **continuations**, using either `call/cc` or any of various delimited continuation operators. See . +* Scheme has excellent support for working with implicit or "first-class" **continuations**, using either `call/cc` or any of various delimited continuation operators. See [the Racket docs](http://docs.racket-lang.org/reference/cont.html?q=shift&q=do#%28part._.Classical_.Control_.Operators%29). In Scheme you can use these forms by default (they're equivalent): @@ -131,7 +131,8 @@ Additionally, the syntax of OCaml and SML is superficially much closer to Haskel There is also a library for using *undelimited* continuations in OCaml, but it's shakier than Oleg's delimited continuation library. -We won't say any more about translating to and from Scheme. +There are some more hints about Scheme [here](/assignment8/) and [here](/week1/). We won't say any more here. + #Haskell and OCaml# @@ -198,6 +199,12 @@ We will however try to give some general advice about how to translate between O type person = name * address;; type 'a personal_data = PD of 'a;; +* When a type only has a single variant, as with PersonalData, Haskell programmers will often use the same name for both the type and the value constructor, like this: + + data PersonalData a = PersonalData a + + The interpreter can always tell from the context when you're using the type name and when you're using the value constructor. + * The type constructors discussed above took simple types as arguments. In Haskell, types are also allowed to take *type constructors* as arguments: data BarType t = Bint (t Integer) | Bstring (t string) @@ -663,6 +670,11 @@ Haskell has more built-in support for monads, but one can define the monads one which can be translated straightforwardly into OCaml. + For more details, see: + + * [Haskell Wikibook on do-notation](http://en.wikibooks.org/wiki/Haskell/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. * In order to do any printing, Haskell has to use a special `IO` monad. So programs will look like this: