Skip to content

Commit dfa12a0

Browse files
committed
Matrix and Vector implement interfaces
1 parent b1ed24b commit dfa12a0

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/FSharpPlus.TypeLevel/Data/Matrix.fs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Matrix< 'Item, 'Row, 'Column > = private { Items: 'Item[,] } with
1616
[<MethodImpl(MethodImplOptions.AggressiveInlining)>]
1717
static member UnsafeCreate (_row: 'm, _column: 'n, items: _[,]) : Matrix<_, 'm, 'n> =
1818
{ Items = items }
19-
(*
19+
2020
interface System.Collections.Generic.IReadOnlyCollection<'Item> with
2121
member this.Count = this.Items.Length
2222
member this.GetEnumerator() = this.Items.GetEnumerator()
@@ -27,7 +27,7 @@ type Matrix< 'Item, 'Row, 'Column > = private { Items: 'Item[,] } with
2727
for j = 0 to (items |> Array2D.length2) - 1 do
2828
yield items.[i,j]
2929
}).GetEnumerator()
30-
*)
30+
3131

3232
[<Struct; StructuredFormatDisplayAttribute("{Items}")>]
3333
type Vector<'Item, 'Length> = private { Items: 'Item[] } with
@@ -36,13 +36,13 @@ type Vector<'Item, 'Length> = private { Items: 'Item[] } with
3636
[<MethodImpl(MethodImplOptions.AggressiveInlining)>]
3737
static member UnsafeCreate (_length: 'n, items: _[]) : Vector<_, 'n> =
3838
{ Items = items }
39-
(*
39+
4040
interface System.Collections.Generic.IReadOnlyList<'Item> with
4141
member this.Count = this.Items.Length
4242
member this.Item with get i = this.Items.[i]
4343
member this.GetEnumerator() = this.Items.GetEnumerator()
4444
member this.GetEnumerator() = (this.Items :> seq<_>).GetEnumerator()
45-
*)
45+
4646

4747
module Vector =
4848
[<MethodImpl(MethodImplOptions.AggressiveInlining)>]

tests/FSharpPlus.Tests/TypeLevel.fs

+20
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,23 @@ module TypeProviderTests =
206206
Assert (Matrix.colLength row1 =^ (Z |> S |> S |> S))
207207
areEqual 5 (Matrix.get Z (S Z) row1)
208208
areEqual [3; 6; 9] (Vector.toList col2)
209+
210+
module TestFunctors1 =
211+
[<Test>]
212+
let applicativeOperatorWorks() =
213+
let v = vector ((fun i -> i + 1), (fun i -> i * 2))
214+
let u = vector (2, 3)
215+
let vu = v <*> u
216+
NUnit.Framework.Assert.IsInstanceOf<Option<Vector<int,S<S<Z>>>>> (Some vu)
217+
CollectionAssert.AreEqual ([|2; 3|], Vector.toArray vu)
218+
219+
module TestFunctors2 =
220+
open FSharpPlus
221+
222+
[<Test>]
223+
let applicativeWorksWithoutSubsumption() =
224+
let v = vector ((fun i -> i + 1), (fun i -> i * 2))
225+
let u = vector (2, 3)
226+
let vu = v <*> u
227+
NUnit.Framework.Assert.IsInstanceOf<Option<Vector<int,S<S<Z>>>>> (Some vu)
228+
CollectionAssert.AreEqual ([|2; 3|], Vector.toArray vu)

0 commit comments

Comments
 (0)