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=300eb61b7375b43ea68b9641e213e3d3f6a668cb;hp=d0f7442cc6b0b3b21e2e984882edd81ebe50d0ec;hb=1c06c5dab40e8cc8bb1bf89bfe65a7d6741d3cbf;hpb=a87f3717596e9b3392498513af3d2d41d40bed7e diff --git a/translating_between_OCaml_Scheme_and_Haskell.mdwn b/translating_between_OCaml_Scheme_and_Haskell.mdwn index d0f7442c..300eb61b 100644 --- a/translating_between_OCaml_Scheme_and_Haskell.mdwn +++ b/translating_between_OCaml_Scheme_and_Haskell.mdwn @@ -183,15 +183,17 @@ We will however try to give some general advice about how to translate between O type Weight = Integer type Person = (Name, Address) -- supposing types Name and Address to be declared elsewhere - then you can use a value of type `Integer` wherever a `Weight` is expected, and vice versa. `newtype` and `data` on the other hand, create genuinely new types. `newtype` is basically just an efficient version of `data` that you can use in special circumstances. `newtype` must always take one type argument and have one value constructor. For example: + then you can use a value of type `Integer` wherever a `Weight` is expected, and vice versa. + + `newtype` and `data` on the other hand, create genuinely new types. `newtype` is basically just an efficient version of `data` that you can use in special circumstances. `newtype` must always take one type argument and have one value constructor. For example: newtype PersonalData a = PD a You could also say: - data PersonalData a = PD a + data PersonalData2 a = PD2 a - And `data` also allows multiple type arguments, and multiple variants and value constructors. + And `data` also allows multiple type arguments, and multiple variants and value constructors. OCaml just uses the one keyword `type` for all of these purposes: @@ -201,7 +203,7 @@ We will however try to give some general advice about how to translate between O * 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 + data PersonalData3 a = PersonalData3 a The interpreter can always tell from the context when you're using the type name and when you're using the value constructor. @@ -673,6 +675,7 @@ Haskell has more built-in support for monads, but one can define the monads one 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.