open System;; type 'a stack = Emp | Apnd of 'a stack * 'a;; // 'Apnd' for "append" let s = Apnd(Apnd(Apnd(Emp,2),3),5);; //instead of Cons(2,Cons(3,Cons(5,Emp))); let rec tolist = function | Emp -> [] | Apnd(s,a) -> a::tolist(s);; let rec tolist2 ax = function | Emp -> ax // ax is the accumulator | Apnd(s,a) -> tolist2 (a::ax) s;; let sl = tolist2 [] s;; Console.WriteLine(sl);; let tolist3 (M:'a stack) = let mutable L:'a list = [] // type annotation is needed here let mutable N = M while N <> Emp do // <> is "not equals": != is used for something else match N with | Apnd(s,x) -> L <- x::L N <- s |_ -> () L;; // I *think* this works