601ecdb1dc461cf574865781ce20245c75b5220b
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 ()
40 let d : Stack<#Foo> = (Empty.Push <| Bar ()).Push <| Bar ()
48 let rec primesSieve sequence =
50 let h = Seq.head sequence
52 yield! primesSieve <| Seq.filter (fun m -> m % h <> 0) sequence
54 let primes = primesSieve <| (Seq.initInfinite id |> Seq.skip 2)
55 printfn "first
primes: %A
" <| (Seq.take 100 primes |> Seq.toList)