adamc@590: fun getOpt (t ::: Type) (o : option t) (v : t) : t = adamc@590: case o of adamc@590: None => v adamc@590: | Some x => x adamc@590: adamc@595: datatype color = Red | White | Blue adamc@595: adamc@595: fun colorToString c = adamc@595: case c of adamc@595: Red => "R" adamc@595: | White => "W" adamc@595: | Blue => "B" adamc@595: adamc@595: val show_color = mkShow colorToString adamc@595: adamc@596: datatype list a = Nil | Cons of a * list a adamc@596: adamc@596: fun delist ls : xbody = adamc@596: case ls of adamc@596: Nil => Nil adamc@596: | Cons (h, t) => {cdata h} :: {delist t} adamc@596: adamc@597: datatype weird = Foo | Bar | Baz of string adamc@597: adamc@597: fun weirdToString w = adamc@597: case w of adamc@597: Foo => "Foo" adamc@597: | Bar => "Bar" adamc@597: | Baz s => s adamc@597: adamc@597: val show_weird = mkShow weirdToString adamc@597: adamc@591: cookie int : int adamc@591: cookie float : float adamc@592: cookie string : string adamc@592: cookie bool : bool adamc@593: cookie pair : int * float adamc@594: cookie option : option int adamc@595: cookie color : color adamc@596: cookie list : list string adamc@597: cookie weird : weird adamc@591: adamc@590: fun main () : transaction page = adamc@590: n <- getCookie int; adamc@591: n <- return (getOpt n 7); adamc@591: sn <- source 6; adamc@591: adamc@591: f <- getCookie float; adamc@591: f <- return (getOpt f 1.23); adamc@591: sf <- source 4.56; adamc@591: adamc@592: s <- getCookie string; adamc@592: s <- return (getOpt s "Hi"); adamc@592: ss <- source "Bye"; adamc@592: adamc@592: b <- getCookie bool; adamc@592: b <- return (getOpt b True); adamc@592: sb <- source False; adamc@592: adamc@593: p <- getCookie pair; adamc@593: p <- return (getOpt p (1, 2.3)); adamc@593: sp <- source (4, 5.6); adamc@593: adamc@594: o <- getCookie option; adamc@594: o <- return (getOpt o (Some 1)); adamc@595: so <- source None; adamc@595: adamc@595: c <- getCookie color; adamc@595: c <- return (getOpt c White); adamc@595: sc <- source Blue; adamc@594: adamc@596: l <- getCookie list; adamc@596: l <- return (getOpt l (Cons ("A", Cons ("B", Nil)))); adamc@596: sl <- source Nil; adamc@596: adamc@597: w <- getCookie weird; adamc@597: w <- return (getOpt w (Baz "TADA!")); adamc@597: sw <- source Foo; adamc@597: adamc@590: return adamc@590: {[n]}}/> adamc@591: CHANGE
adamc@591: adamc@591: {[f]}}/> adamc@591: CHANGE
adamc@592: adamc@592: {[s]}}/> adamc@592: CHANGE
adamc@592: adamc@592: {[b]}}/> adamc@592: CHANGE
adamc@593: adamc@593: {[p.1]}, {[p.2]}}/> adamc@593: CHANGE
adamc@594: adamc@595: return None adamc@594: | Some x => return {[x]}}/> adamc@595: CHANGE
adamc@595: adamc@595: {[c]}}/> adamc@595: CHANGE
adamc@596: adamc@596: {delist l}}/> adamc@596: CHANGE
adamc@597: adamc@597: {[w]}}/> adamc@597: CHANGE
adamc@590: