comparison tests/list.ur @ 757:fa2019a63ea4

Basis.list
author Adam Chlipala <adamc@hcoop.net>
date Thu, 30 Apr 2009 11:07:29 -0400
parents 71bafe66dbe1
children 8323c1beef2e
comparison
equal deleted inserted replaced
756:8ce31c052dce 757:fa2019a63ea4
1 datatype list a = Nil | Cons of a * list a 1 fun isNil (t ::: Type) (ls : list t) =
2 case ls of
3 Nil => True
4 | _ => False
2 5
3 val isNil = fn t ::: Type => fn ls : list t => 6 fun delist (ls : list string) : xbody =
4 case ls of Nil => True | _ => False 7 case ls of
8 Nil => <xml>Nil</xml>
9 | Cons (h, t) => <xml>{[h]} :: {delist t}</xml>
5 10
6 val show = fn b => if b then "True" else "False" 11 fun main () = return <xml><body>
12 {[isNil (Nil : list bool)]},
13 {[isNil (Cons (1, Nil))]},
14 {[isNil (Cons ("A", Cons ("B", Nil)))]}
7 15
8 val rec delist : list string -> xml body [] [] = fn x => 16 <p>{delist (Cons ("X", Cons ("Y", Cons ("Z", Nil))))}</p>
9 case x of 17 </body></xml>
10 Nil => <body>Nil</body>
11 | Cons (h, t) => <body>{cdata h} :: {delist t}</body>
12
13 val main : unit -> page = fn () => <html><body>
14 {cdata (show (isNil (Nil : list bool)))},
15 {cdata (show (isNil (Cons (1, Nil))))},
16 {cdata (show (isNil (Cons ("A", Cons ("B", Nil)))))}
17
18 <p>{delist (Cons ("X", Cons ("Y", Cons ("Z", Nil))))}</p>
19 </body></html>