I stumbled upon some "odd behaviour". I was using the F# interactive to test some code and wrote
Seq.zip "ACT" "GGA" |> Seq.map ((<||) compare)
// val it : seq<int> = seq [-1; -1; 1]
Then I wanted to make a function out of it and wrote
let compute xs ys = Seq.zip xs ys |> Seq.map ((<||) compare)
// val compute : xs:seq<'a> -> xs:seq<'a> -> seq<int> when 'a : comparison
That generalized the first snippet of code and I thought that was a good thing... until I tried to use it
compute "ACT" "GGA"
// val it : seq<int> = seq [-6; -4; 19]
So somehow compare
acts differently for the "same thing" when there is a different "point of view" (explicit type vs generics)
I know how to solve it: either by making the type explicit
let compute (xs: #seq<char>) // ... or char seq or string
Or keeping the type generic and composing with the sign
function
let compute (* ... *) ((<||) compare >> sign)
tl;dr the question is where does the difference in behavior come from exactly?