comparison tests/option.lac @ 198:ab86aa858e6c

'Option' datatype encoding
author Adam Chlipala <adamc@hcoop.net>
date Sat, 09 Aug 2008 19:23:31 -0400
parents
children
comparison
equal deleted inserted replaced
197:b1b9bcfd8c42 198:ab86aa858e6c
1 datatype option a = None | Some of a
2
3 val none_Hi : option string = None
4 val some_Hi = Some "Hi"
5 val none_some_Hi : option (option string) = None
6 val some_some_Hi = Some some_Hi
7
8 val show = fn x => case x of None => "None" | Some x => x
9
10 val show2 = fn x => case x of None => "None'" | Some x => show x
11
12 val page = fn x => <html><body>
13 {cdata (show x)}
14 </body></html>
15
16 val page2 = fn x => <html><body>
17 {cdata (show2 x)}
18 </body></html>
19
20 val main : unit -> page = fn () => <html><body>
21 <li><a link={page none_Hi}>None1</a></li>
22 <li><a link={page some_Hi}>Some1</a></li>
23 <li><a link={page2 none_some_Hi}>None2</a></li>
24 <li><a link={page2 some_some_Hi}>Some2</a></li>
25 </body></html>