Your not the first person caught out by this. In fact, when you use a pattern match in this way the field in the record will get bound into the him identifier rather than testing for equality. You need add a when guard if you want a dynamic check for equality:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
open System

type Couple = { Him: String ; Her: String }
let couples = [ { Him = "Roméo" ; Her = "Juliette"} ; 
                      { Him = "Abélard" ; Her = "Héloïse"} ;
                      { Him = "Paul" ; Her = "Virginie" } ;
                      { Him = "Harry" ; Her = "Dors" }
                   ]

let rec FindHim l x =
    match l with
    | { Him = him ; Her = her } :: tail when him = x -> her
    | _ :: tail -> (FindHim tail x) // Compiler warning here <---
    | [] -> ""

HTH,
Robert

By on 11/26/2007 6:40 AM ()

Thanks a lot, Robert!
I wouldn't have found this by myself

Philippe

By on 11/26/2007 6:47 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