Last active
August 29, 2015 13:55
-
-
Save timvw/8717796 to your computer and use it in GitHub Desktop.
This file contains 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
let (|Array|_|) pattern toMatch = | |
let patternLength = Array.length pattern | |
let toMatchLength = Array.length toMatch | |
let tailLength = toMatchLength - patternLength | |
if patternLength > toMatchLength then | |
None | |
else | |
let firstElementsAreEqual = [ 0 .. (patternLength - 1) ] |> Seq.forall (fun i -> pattern.[i] = toMatch.[i]) | |
if firstElementsAreEqual then | |
Some(Array.sub toMatch patternLength tailLength) | |
else | |
None | |
match [|1;2;3|] with | |
| Array [|1|] tail -> sprintf "bingo %i" (tail |> Array.sum) // the tail is [|2;3|] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment