Here is my initial take on the SML code in above:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#light

type Stack<'a> =


    abstract Empty: Stack<'a>


    abstract IsEmpty: bool


    abstract Cons: 'a -> Stack<'a>


    abstract Head: 'a


    abstract Tail: Stack<'a>

module StackOps =


    let isEmpty (s: Stack<_>) = s.IsEmpty


    let cons (s: Stack<_>) x = s.Cons(x)


    let hd (s: Stack<_>) = s.Head


    let tl (s: Stack<_>) = s.Tail

let rec ListStack(list) =


    { new Stack<'a> with


       override s.Empty = ListStack([])


       override s.IsEmpty = list = []


       override s.Cons x = ListStack(x::list)


       override s.Head = List.hd list


       override s.Tail = ListStack(List.tl list) }

I'd love to hear your comments on how accurately or inaccurately this approach represents the original SML!

By on 8/15/2008 5:30 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper