Note that there are some explanatory texts on larger screens.

plurals
  1. PONullReferenceException on type initializer
    primarykey
    data
    text
    <p>I was playing with F# types and datastructures in the following code (I'm using Monodevelop on a Mac and this only happens in the Interactive):</p> <pre><code>type UnbalancedSet&lt;'a&gt; = | E | T of UnbalancedSet&lt;'a&gt; * 'a * UnbalancedSet&lt;'a&gt; let rec insert x = function | E -&gt; T(E, x, E) | T(a, y, b) as s -&gt; if x &lt; y then T(insert x a, y, b) elif x &gt; y then T(a, y, insert x b) else s </code></pre> <p>It works great with simple types as ints floats and chars but when it comes to strings or tuples it gives the following error:</p> <pre><code>let a = insert (3, 9) E;; System.TypeInitializationException: An exception was thrown by the type initializer for UnbalancedSet`1 ---&gt; 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 &lt;filename unknown&gt;:0 --- End of inner exception stack trace --- at &lt;StartupCode$FSI_0004&gt;.$FSI_0004.main@ () [0x00000] in &lt;filename unknown&gt;:0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&amp;) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in &lt;filename unknown&gt;:0 Stopped due to error </code></pre> <p>I don't understand what's going on. I expected this code to work since the type is comparable. Any clues?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload