3 datatype 'a clist
' = Cons
of 'a
* 'a clist ref
4 withtype 'a clist
= 'a clist
' option
7 fun ccons (h
, t
) = SOME (Cons (h
, ref t
))
9 fun match cl nilCase consCase
=
12 |
SOME (Cons (h
, t
)) => consCase (h
, !t
)
17 | h
::t
=> ccons (h
, fromList t
)
22 val cl
= SOME (Cons (x
, r
))
35 (fn (_
,t
) => length
' (t
, n
+ 1))
37 fun length cl
= length
' (cl
, 0)
41 val cl
= CList
.repeat #
"x"
42 val n
= CList
.length cl
45 NONE
=> print
"NONE\n"
46 | SOME n
=> print (concat
["SOME ", Int.toString n
, "\n"])
48 val cl
= CList
.fromList
[1,2,3,4,5,6,7,8,9]
49 val n
= CList
.length cl
52 NONE
=> print
"NONE\n"
53 | SOME n
=> print (concat
["SOME ", Int.toString n
, "\n"])