0 people like it.

brute_force_tail_array

brute force pattern building for an array tail

1: 
2: 
3: 
4: 
5: 
6: 
7: 
let nums = [|1;2;3|]

let initial = [|1;2|]

let pattern = Array.concat [initial ;Array.sub nums (Array.length initial) ((Array.length nums) - (Array.length initial)) ]

match nums with pattern -> "bingo"
val nums : int []

Full name: Script.nums
val initial : int []

Full name: Script.initial
val pattern : int []

Full name: Script.pattern
module Array

from Microsoft.FSharp.Collections
val concat : arrays:seq<'T []> -> 'T []

Full name: Microsoft.FSharp.Collections.Array.concat
val sub : array:'T [] -> startIndex:int -> count:int -> 'T []

Full name: Microsoft.FSharp.Collections.Array.sub
val length : array:'T [] -> int

Full name: Microsoft.FSharp.Collections.Array.length
val pattern : int []
Raw view Test code New version

More information

Link:http://fssnip.net/lv
Posted:10 years ago
Author:timvw
Tags: ?