Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# on Mono and Windows - discrepancy with simple function

Tags:

mono

f#

Can someone check my sanity here please. Given this simple function:

let filterOut item l =
  l |> List.filter (fun t -> not (t = item)) 

let f = 
  ["1";"2";"3"]
  |> filterOut "3"

Evaluating the above in FSI produces the following:

  1. Xamarin Studio with mono 4.0.3 on Mac OS X

    val f : string list = ["1"]

  2. Visual Studio 2013

    val f : string list = ["1"; "2"]

If the input is a list of ints or chars - then it works as expected and both platforms produce identical results. Also if I specify filterOut to only work with strings it correctly produces identical values. Like so:

 let filterOut item l:list<string> =
   l |> List.filter (fun t -> not (t = item)) 

Even the following code with XS on OS X:

let filterOut item l =
  l |> List.filter (fun t -> not (t = item)) 

let f = 
  ["1";"2";"3"]
  |> filterOut "foobar"

outputs:

val f : string list = ["1"]

I have compared the IL between the XS and VS compiled code and they appear identical. So it seems like a runtime discrepancy. If there something going on here with List.Filter and generic comparison with strings on Mono?

EDIT: If I add "inline" to the filterOut function I also get correct results on both platforms (expected output on OS X). Again it seems something is wrong with the generic comparer on the Mono runtime.

like image 597
Kevin Avatar asked Jul 28 '15 13:07

Kevin


1 Answers

(1 month later) Tested on latest Mono 4.2.0 and now works as expected.

like image 87
Kevin Avatar answered Nov 11 '22 20:11

Kevin