Hm, I'm a little unclear what you're trying to do, but here's some code that may inspire.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 

type X =
    | I of int
    | S of string

let rec (|Nums|_|) l =
    match l with
    | [] -> None
    | (I x)::t -> 
        match t with 
        | Nums(xs, rest) -> Some(x :: xs, rest)
        | _ -> Some([x], t)
    | _ -> None

let stuff = [ I 1; I 2; I 3; S "four" ]
let things = [ S "a"; S "b"; I 3 ]
let leadingInts l =
    match l with
    | Nums(xs, rest) -> printfn "%A   ---   %A" xs rest
    | _ -> printfn "no leading ints"
leadingInts stuff
leadingInts things
By on 4/9/2010 8:10 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper