X-Git-Url: http://git.euphorik.ch/?p=fsharp-ref.git;a=blobdiff_plain;f=FSharpRef%2FFunctional.fs;h=a793722b7d57c38095c85c47d71427155a9aa27b;hp=424dc3517e5dba9050d6b2b2e7d804b434e02016;hb=bc9b618a8f6db5806b1d9c27cbae59eaa1ec70f2;hpb=ac61fd49bf7897adbb18d2ae0f3bd843311a4ccf diff --git a/FSharpRef/Functional.fs b/FSharpRef/Functional.fs index 424dc35..a793722 100644 --- a/FSharpRef/Functional.fs +++ b/FSharpRef/Functional.fs @@ -3,9 +3,6 @@ open System.IO open System.Linq -// For dynmic typing. To print anything in our case. -let inline print a = printfn "%A" a - // Write something on a file. let appendFile (filename: string) (text: string) = use sw = new StreamWriter(filename, true) @@ -59,10 +56,19 @@ let deckOfCards = yield NumCard(n, suit) ] -// Records. -type Person = { First: string; Last: string; Age: int } +// Records with custom equality. +[] +type Person = + { First: string; Last: string; Age: int } + override this.Equals(other) = + match other with + | :? Person as p -> p.First = this.First && p.Last = this.Last + | _ -> false + override this.GetHashCode() = + this.First.GetHashCode() ^^^ this.Last.GetHashCode() + let steve = { First = "Steve"; Last = "Holt"; Age = 17 } -let steves'twin = { steve with First = "Paul" } +let stevesTwin = { steve with First = "Paul" } // Queries. Should be used with SQL or other external data sources. let youngPersonNames persons =