X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=translating_between_OCaml_Scheme_and_Haskell.mdwn;fp=translating_between_OCaml_Scheme_and_Haskell.mdwn;h=4b0f715432c96dff25a2eed522f92bb7adcc985a;hp=ea4079e954dbefbbcc1c74dffd2caed93d6708f2;hb=7d1a4657f55750d3eb1571a498573cf0faada29c;hpb=047287e7095a4f7001b9b7154a08da7198e45499 diff --git a/translating_between_OCaml_Scheme_and_Haskell.mdwn b/translating_between_OCaml_Scheme_and_Haskell.mdwn index ea4079e9..4b0f7154 100644 --- a/translating_between_OCaml_Scheme_and_Haskell.mdwn +++ b/translating_between_OCaml_Scheme_and_Haskell.mdwn @@ -42,14 +42,17 @@ Additionally, the syntax of OCaml and SML is superficially much closer to Haskel * **Type Variants and Pattern Matching** If you want to reproduce this kind of OCaml code: - type lambda_expression = Var of char | Lam of char * lambda_expression | App of lambda_expression * lambda_expression;; + # type lambda_expression = Var of char | Lam of char * lambda_expression | App of lambda_expression * lambda_expression;; - let rec free_vars (expr : lambda_expression) : char list = + # let rec free_vars (expr : lambda_expression) : char list = match expr with | Var label -> [label] | Lam (label, body) -> remove label (free_vars body) | App (left, right) -> merge (free_vars left) (free_vars right);; + # free_vars (Lam ('x', (App (Var 'x', Var 'y'))));; + - : char list = ['y'] + in Scheme, you have two choices. First, the quick hack: ; we use the symbols 'var and 'lam as tags, and assume @@ -85,6 +88,8 @@ Additionally, the syntax of OCaml and SML is superficially much closer to Haskel (lam (label body) (remove label (free-vars body))) (app (left right) (remove-duplicates (append (free-vars left) (free-vars right)))))) + (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 .