mirror of
https://github.com/Smaug123/fsharp-vectors
synced 2025-10-05 11:38:38 +00:00
If Don had intended us not to use operators, he would have left them out of the language
This commit is contained in:
@@ -15,20 +15,17 @@ module TestVector =
|
|||||||
|> Vector.cons 6
|
|> Vector.cons 6
|
||||||
v1 |> Vector.toList |> shouldEqual [6 ; 5 ; 3]
|
v1 |> Vector.toList |> shouldEqual [6 ; 5 ; 3]
|
||||||
|
|
||||||
let v2 = Vector.empty |> Vector.cons "hi" |> Vector.cons "bye"
|
let v2 = "bye" ** "hi" ** -()
|
||||||
v2 |> Vector.toList |> shouldEqual ["bye" ; "hi"]
|
v2 |> Vector.toList |> shouldEqual ["bye" ; "hi"]
|
||||||
|
|
||||||
[<Test>]
|
[<Test>]
|
||||||
let ``Pattern matching`` () =
|
let ``Pattern matching`` () =
|
||||||
match Vector.empty with
|
match -() with
|
||||||
| Empty () -> ()
|
| Empty () -> ()
|
||||||
//| Vec (a, b) -> failwith "" -- doesn't compile
|
//| Vec (a, b) -> failwith "" -- doesn't compile
|
||||||
|
|
||||||
let v1 =
|
let v1 =
|
||||||
Vector.empty
|
6 ** 5 ** 3 ** -()
|
||||||
|> Vector.cons 3
|
|
||||||
|> Vector.cons 5
|
|
||||||
|> Vector.cons 6
|
|
||||||
|
|
||||||
match v1 with
|
match v1 with
|
||||||
| Vec (a , b) ->
|
| Vec (a , b) ->
|
||||||
@@ -45,10 +42,7 @@ module TestVector =
|
|||||||
[<Test>]
|
[<Test>]
|
||||||
let ``Vector concatenation`` () =
|
let ``Vector concatenation`` () =
|
||||||
let v1 =
|
let v1 =
|
||||||
Vector.empty
|
6 ** 5 ** 3 ** -()
|
||||||
|> Vector.cons 3
|
|
||||||
|> Vector.cons 5
|
|
||||||
|> Vector.cons 6
|
|
||||||
|
|
||||||
let twice = Vector.append v1 v1
|
let twice = Vector.append v1 v1
|
||||||
let otherTwice =
|
let otherTwice =
|
||||||
|
@@ -74,4 +74,7 @@ module Patterns =
|
|||||||
let (|Vec|) (Vector v : Vector<'a, S<'n>>) : 'a * Vector<'a, 'n> =
|
let (|Vec|) (Vector v : Vector<'a, S<'n>>) : 'a * Vector<'a, 'n> =
|
||||||
List.head v, Vector (List.tail v)
|
List.head v, Vector (List.tail v)
|
||||||
|
|
||||||
let (|Empty|) (_ : Vector<'a, Z>) = ()
|
let (|Empty|) (_ : Vector<'a, Z>) = ()
|
||||||
|
|
||||||
|
let ( ~- ) () : Vector<'a, Z> = Vector.empty<'a>
|
||||||
|
let ( ** ) (x : 'a) (v : Vector<'a, 'n>) = Vector.cons x v
|
||||||
|
Reference in New Issue
Block a user