F# integer comparison

Viewed 1471

Given a list int from -273 to 5526, I want to print the closest integer to zero. In case of you have equality (n and -n) we should take n.

let temps = // this contains => 1 -2 -8 4 5

let (|Greater|_|) a b = if a > b then Some() else None
let (|Smaller|_|) a b = if a < b then Some() else None

let compareTemperatures a b = 
   let distanceA = abs a 
   let distanceB = abs b
   match distanceA with
   | Greater distanceB -> b
   | Smaller distanceB -> a
   | _ -> abs a

printfn "%i" (temps |> Seq.reduce compareTemperatures)

And that returns -8 instead of 1. It seems correct to me and I can't find the bug but I'm new to F# so I might have make a mistake anywhere and can't see it :(

Thanks in advance

3 Answers
Related