Skip to content

Instantly share code, notes, and snippets.

@baronfel
Last active January 2, 2018 22:56
Show Gist options
  • Save baronfel/1a35c6a84afbb20c0875be43c3be6a48 to your computer and use it in GitHub Desktop.
Save baronfel/1a35c6a84afbb20c0875be43c3be6a48 to your computer and use it in GitHub Desktop.
hash comparisons for F# collection types
// different hashes because different Seq object instances
> hash ([|1;2;3|] |> Seq.ofArray);;
val it : int = 851672095
> hash ([|1;2;3|] |> Seq.ofArray);;
val it : int = -1641179064
// same hash because Seq.ofList is just returning the list cast to IEnumerable<'t>
> hash ([1;2;3] |> Seq.ofList);;
val it : int = 1956583134
> hash ([1;2;3] |> Seq.ofList);;
val it : int = 1956583134
// same hash because list literals are structurally comparable
> hash [1;2;3];;
val it : int = 1956583134
> hash [1;2;3];;
val it : int = 1956583134
// same for F# array literals (though maybe not .Net BCL arrays?
> hash [|1;2;3|];;
val it : int = 6327
> hash [|1;2;3|];;
val it : int = 6327
// different here for the same reason as the first example
> hash (seq {1..3});;
val it : int = 1600387598
> hash (seq {1..3});;
val it : int = -606300310
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment