diff options
-rw-r--r-- | doc/intro.ur | 19 | ||||
-rw-r--r-- | src/c/static.c | 21 | ||||
-rw-r--r-- | src/tutorial.sml | 2 |
3 files changed, 32 insertions, 10 deletions
diff --git a/doc/intro.ur b/doc/intro.ur index d474a1e1..b9b15b72 100644 --- a/doc/intro.ur +++ b/doc/intro.ur @@ -73,3 +73,22 @@ fun compose [a] [b] [c] (f : b -> c) (g : a -> b) (x : a) : c = f (g x) (* begin eval *) compose inc inc 3 (* end *) + +(* The "option" type family is like ML's "option" or Haskell's "maybe." Note that, while Ur follows most syntactic conventions of ML, one key difference is that type families appear before their arguments, as in Haskell. *) + +fun predecessor (n : int) : option int = if n >= 1 then Some (n - 1) else None + +(* begin hide *) +fun show_option [t] (_ : show t) : show (option t) = + mkShow (fn x => case x of + None => "None" + | Some x => "Some(" ^ show x ^ ")") +(* end *) + +(* begin eval *) +predecessor 6 +(* end *) + +(* begin eval *) +predecessor 0 +(* end *) diff --git a/src/c/static.c b/src/c/static.c index 76b04e45..6be67237 100644 --- a/src/c/static.c +++ b/src/c/static.c @@ -25,15 +25,18 @@ int main(int argc, char *argv[]) { ctx = uw_init(0, NULL, log_debug); uw_set_app(ctx, &uw_application); - fk = uw_begin(ctx, argv[1]); - - if (fk == SUCCESS) { - uw_print(ctx, 1); - puts(""); - return 0; - } else { - fprintf(stderr, "Error!\n"); - return 1; + + while (1) { + fk = uw_begin(ctx, argv[1]); + + if (fk == SUCCESS) { + uw_print(ctx, 1); + puts(""); + return 0; + } else if (fk != UNLIMITED_RETRY) { + fprintf(stderr, "Error: %s\n", uw_error_message(ctx)); + return 1; + } } } diff --git a/src/tutorial.sml b/src/tutorial.sml index f6b9defb..8d60ed11 100644 --- a/src/tutorial.sml +++ b/src/tutorial.sml @@ -79,7 +79,7 @@ fun fixupFile (fname, title) = else let val (befor', after) = Substring.position " </span><span class=\"comment-delimiter\">*)</span>" - (Substring.slice (after, 64, NONE)) + (Substring.slice (after, 64, NONE)) in if Substring.isEmpty after then TextIO.outputSubstr (outf, source) |