X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=rosetta1.mdwn;h=a84719588b4242e5cbbbc1d6730daad686e42e8b;hp=e353451112c179032336e5b460cd7b6be40cecc6;hb=c6fe7737f03addc98e31b044f1b2d855498a0dfb;hpb=07ebc9292a8db8b98707232d2d01717293f473e9 diff --git a/rosetta1.mdwn b/rosetta1.mdwn index e3534511..a8471958 100644 --- a/rosetta1.mdwn +++ b/rosetta1.mdwn @@ -1,5 +1,7 @@ [[!toc levels=2]] +More details are also available on these [[two|/rosetta2]] [[pages|/rosetta3]]. (But some information is only discussed below; the others aren't supersets of this page.) + ## Can you summarize the differences between your made-up language and Scheme, OCaml, and Haskell? ## The made-up language we wet our toes in in week 1 is called Kapulet. (I'll tell you [the story behind its name](/images/randj.jpg) sometime.) The purpose of starting with this language is that it represents something of a center of gravity between Scheme, OCaml, and Haskell, and also lacks many of their idiosyncratic warts. One downside is that it's not yet implemented in a form that you can run on your computers. So for now, if you want to try out your code on a real mechanical evaluator, you'll need to use one of the other languages. @@ -78,7 +80,7 @@ These relations are written in Haskell and OCaml as `&&`, `||`, and `not`. (Hask The values that are written `'true` and `'false` in Kapulet are written in Haskell as `True` and `False`, and in OCaml as just `true` and `false`. (It'd be more consistent with OCaml's other naming policies for them to have said True and False, but they didn't.) These are written `#t` and `#f` in Scheme, but in Scheme in many contexts any value that isn't `#f` will behave as though it were `#t`, even values you might think are more "false-like", like `0` and the empty list. Thus `(if 0 'zero 'nope)` will evaluate to `'zero`. -Some Scheme implementations, such as Racket, permit `#true` and `#false` as synonyms for `#t` and `#f`. +Some Scheme implementations, such as Racket, permit `#true` and `#false` as synonyms for `#t` and `#f`. (These aliases are also mandated in "version 7", r7rs, of the Scheme standard.) Scheme also recognizes the values `'true` and `'false`, but it treats `'false` as distinct from `#f`, and thus as a "truth-like" value, like all of its other values that aren't `#f`. Kapulet essentially took Scheme's `boolean` values and collapsed them into being a subtype of its `symbol` values. @@ -110,7 +112,13 @@ Scheme has no infix operators. It ruthlessly demands that all functions to be ap (+ 3 2) -and the like. Moreover, in Scheme parentheses are never optional and never redundant. In contexts like this, the parentheses are necessary to express that the function is being applied; `+ 3 2` on its own is not a complete Scheme expression. And if the `+` were surrounded by its own parentheses, as in: +and the like. Here is an example where the function to be applied is the result of evaluating a more complex expression: + + ((if #t + *) 3 2) + +which will evaluate to `5`, not `6`. + +In Scheme the parentheses are never optional and never redundant. In expressions like `(+ 3 2)`, the parentheses are necessary to express that the function is being applied; `+ 3 2` on its own is not a complete Scheme expression. And if the `+` were surrounded by its own parentheses, as in: ((+) 3 2) @@ -209,7 +217,7 @@ Fourth, in Kapulet, `( - 10)` expresses λ `x. x - 10` (consistently with ( - 2) # ( - 2) 10 == 8 (0 - ) ( - ) (5, 3) - + and here are their translations into natural Haskell: @@ -511,6 +519,7 @@ Note there is no closing `end` or `}`. You can enclose the whole expression in p | 1 -> result1 | x -> resultx + The syntax for [[guards|topics/week1_kapulet_advanced#guards]] and [[as-patterns|topics/week1_kapulet_advanced#as-patterns]] also only varies slightly between these languages: # Kapulet @@ -773,7 +782,7 @@ Notice that this form ends with `end`, not with `in result`. The above is roughl pat1 match expr1; ... in ... # rest of program or library - + That is, the bindings initiated by the clauses of the `let` construction remain in effect until the end of the program or library. They can of course be "hidden" by subsequent bindings to new variables spelled the same way. The program: # Kapulet