次のコードで F# の型とデータ構造を使用していました (Mac で Monodevelop を使用していますが、これはインタラクティブでのみ発生します)。
type UnbalancedSet<'a> =
| E
| T of UnbalancedSet<'a> * 'a * UnbalancedSet<'a>
let rec insert x = function
| E -> T(E, x, E)
| T(a, y, b) as s ->
if x < y then T(insert x a, y, b)
elif x > y then T(a, y, insert x b)
else s
ints float および chars などの単純な型でうまく機能しますが、文字列またはタプルになると、次のエラーが発生します。
let a = insert (3, 9) E;;
System.TypeInitializationException: An exception was thrown by the type initializer for UnbalancedSet`1 ---> System.NullReferenceException: Object reference not set to an instance of an object
at FSI_0004+UnbalancedSet`1[System.Tuple`2[System.Int32,System.Int32]]..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at <StartupCode$FSI_0004>.$FSI_0004.main@ () [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,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] in <filename unknown>:0
Stopped due to error
何が起こっているのかわかりません。型が同等であるため、このコードが機能することを期待していました。手がかりはありますか?