2a768cda85b5c8fb0cbe9b55152cbd229c9b41d1
5 | Elem of 'a
* Stack<'a>
7 member this.Push a = Elem (a, this)
11 | Empty -> failwith "Empty stack!"
14 | Elem (_, rest) -> rest
15 | Empty -> failwith "Empty stack!"
16 override this.ToString () =
18 | Elem (e, rest) -> e.ToString() + "," + rest.ToString()
21 type Foo () = class end
22 type Bar () = inherit Foo ()
26 let a = (((Empty.Push "hello").Push "world").Push "it's
fun").Pop
28 assert (a.ToString () = "world
,hello
,Empty")
30 let b = ((Empty.Push 1).Push 3)
31 printfn "b.Top: %O
" b.Top
34 let c : Stack<Bar> = (Empty.Push <| Bar ()).Push <| Bar ()
35 c.Top :> Bar |> ignore
36 c.Top :> Foo |> ignore
38 let d : Stack<#Foo> = (Empty.Push <| Bar ()).Push <| Bar ()
39 d.Top :> Bar |> ignore
43 let rec sieve sequence =
45 let h = Seq.head sequence
47 yield! sieve <| Seq.filter (fun m -> m % h <> 0) sequence
49 let primes = sieve <| (Seq.initInfinite id |> Seq.skip 2)
50 printfn "first
primes: %A
" <| (Seq.take 100 primes |> Seq.toList)