Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

An immediate reason is that some variants can be either ints or boxed. eg:

  type t = One             (* represented as int 0 (0b01) *)
         | Two             (* represented as int 1 (0b11) *)
         | Pair of t * t   (* boxed (ie. pointer) *)
The representation used by OCaml is quite subtle. There's a distinction between the very rich types known at compile time which are almost all erased, and the little bit of information that is needed at runtime mainly by the garbage collector.

Here are some links to how it all works:

https://dev.realworldocaml.org/runtime-memory-layout.html https://rwmj.wordpress.com/2009/08/04/ocaml-internals/ https://web.archive.org/web/20210412024831/http://caml.inria...



Ah yes, I wasn't thinking about the gc. That makes more sense now. Thanks!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: