title: (Lazy) Haskell undefined/bottom in OCaml
body: <p>Haskell has a really swell <code>undefined</code> value, which lazily raises an exception (upon evaluation). Ocaml is of course strict, so <a href="https://rosettacode.org/wiki/Undefined_values#OCaml" rel="noreferrer">as far as I can tell there is no equivalent of Haskell's <code>undefined</code></a>. This is unfortunate though, because it means there is no bottom type for values. Let's say I wanted an</p>
  
  <pre><code>val a : int
  </code></pre>
  
  <p>I could of course do</p>
  
  <pre><code>let a = failwith "undefined"
  let () =
    print_string "something unrelated\n"
  </code></pre>
  
  <p>And this happily compiles. Unfortunately, upon running it we get the undefined exception (which is expected).</p>
  
  <p>What I want is to let <code>a</code> be a bottom/<code>undefined</code> value without changing its type (so things like <code>Lazy</code> won't work). Is this possible?</p>
  
  <p><strong>extra details:</strong>
  So what I'm asking for probably sounds fairly silly. To curtail any commentary on why I shouldn't be doing this, allow me to briefly describe my use case. I'm writing a script that modifies the AST of an <code>mli</code> file to produce a "empty" <code>ml</code> file which matches its signatures. For the general case, it's possible to have <code>val a : int</code> in your <code>mli</code> so I need a way to generically synthesize a bottom type. <code>failwith "undefined"</code> works if all I needed was for compilation to succeed. But unfortunately, I also need to link this <code>ml</code> file against an OUnit test suite and run it (obviously the suite will fail, but the purpose is to be able to run it with <code>-list-test</code> so I can programmatically get a list of all tests).</p>
  
  <p><strong>more details:</strong>
  I recognize that the proper way to solve this (probably) is to write a function which can generate the bottom type for any generic type. For the builtin primitives (and <code>list</code>, <code>option</code>, etc.) this is simple enough (just verbose). This becomes more complicated with records (perhaps defined in the stdlib, but also may be defined in the same file or a different package). To handle this my AST transformer then needs to have a complete understanding of the OCaml type system and file importing strategies for packages, which is a lot more logic than I want to/should include in it.</p>