Created
June 26, 2012 05:57
-
-
Save einblicker/2993628 to your computer and use it in GitHub Desktop.
eliminating array bound checking in F#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ElimArrayBoundCheck = | |
type BIndex<'Tag>(idx) = | |
member this.Idx = idx | |
type BArray<'Tag, 'T>(arr : 'T[]) = | |
member this.lookup(bidx : BIndex<'Tag>) = arr.[bidx.Idx] | |
type C<'T, 'R> = interface | |
abstract s<'Tag> : BIndex<'Tag> * BArray<'Tag, 'T> -> 'R | |
abstract f : 'R | |
end | |
let check (arr : 'T[]) (idx : int) (c : C<'T, 'Result>) = | |
c.f(BIndex(idx), BArray(arr)) | |
open ElimArrayBoundCheck | |
let main _ = | |
check [| 1; 2; 3 |] 1 { new C.C<_, _> with | |
member this.f(bidx1, barr1) = | |
check [| 1; 2; 3 |] 1 { new C.C<_, _> with | |
member this.f(bidx2, barr2) = | |
barr1.lookup(bidx1) |> ignore | |
barr2.lookup(bidx2) |> ignore | |
//barr2.lookup(bidx1) |> ignore | |
//barr1.lookup(bidx2) |> ignore | |
} | |
} | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment