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] ;;
source share