Invalid IL Code - F #

I am new to F # and I am trying to write a function that computes a set of parameters.

I get an error from Mono (running this on Mac) below.

For example, I would pass calcPowerSet ([1; 2; 3], []) to run the function. Any ideas on how to solve the problem?

  System.InvalidProgramException: Invalid IL code in FSI_0010: calcPowerSet (Microsoft.FSharp.Collections.List`1, Microsoft.FSharp.Collections.List`1): IL_005d: stind.r4  


   at FSI_0010.calcPowerSet [Int32] (Microsoft.FSharp.Collections.List`1 _arg1_0, Microsoft.FSharp.Collections.List`1 _arg1_1) [0x00000] 
   at. $ FSI_0011._main () [0x00000] 
   at (wrapper managed-to-native) System.Reflection.MonoMethod: InternalInvoke (object, object [], System.Exception &)
   at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object [] parameters, System.Globalization.CultureInfo culture) [0x00000] 
 stopped due to error

code:

  let rec calcPowerSet = function
  |  ([], []) -> [[]]
  |  ((head :: tail), (cHead :: cTail)) -> 
   calcPowerSet (tail, (cHead :: cTail)) @ calcPowerSet (tail, (head :: cHead :: cTail))
  |  ((head :: tail), []) -> 
   calcPowerSet (tail, []) @ calcPowerSet (tail, [head])
  |  ([], collect) -> [collect] ;;
+4
source share
2 answers

I have no idea why this does not work (I got the same result), but if you rewrite it as:

let calcPowerSet = let rec innerCalc = function | ([], []) -> [[]] | ((head::tail), (cHead::cTail)) -> innerCalc (tail, (cHead::cTail)) @ innerCalc (tail, (head::cHead::cTail)) | ((head::tail), []) -> innerCalc (tail, []) @ innerCalc (tail, [head]) | ([], collect) -> [collect] innerCalc 

It seems to work fine under Mac (intel) with Mono 2.4 and F # 1.9.6.2

+2
source

FYI, it turns out, the F # team knows about this error, this is a bug in Mono 2.4, which the Mono team knows about (dunno, if it is still fixed).

+2
source

All Articles