From 4b54ea891652138a8d58399bbbfdbb852b70eabd Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Fri, 15 Jul 2011 18:55:58 -0400 Subject: Make 'static' protocol handle unlimited retry --- doc/intro.ur | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'doc/intro.ur') 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 *) -- cgit v1.2.3