Ocaml representation of values - Atoms

霸气de小男生 提交于 2019-12-12 12:11:06

问题


I looked at the internal representation of some OCaml values. The representation of an empty array is an atom(0), i.e. a block with tag=0 and size=0. Empty arrays of floats are represented by an atom(0) too.

Is there any OCaml value represented by an atom with tag > 0? If not: for what purpose the OCaml bytecode set contains the ATOM n instruction?


回答1:


A tag > 0 is used for constructors with arguments, which would make them not atoms. Constructors without arguments on the other hand are stored as int instead of blocks so again not atoms. So I think atom(0) is not used. Except ...

What about having a constructor with inline record that is empty?

# type t = A of int | B of { };;
Error: Syntax error

Seems empty records are not allowed. I can't think of another way to create a 0 size block with tag other than creating such a block directly. But that wouldn't be using the ATOM instruction.



来源:https://stackoverflow.com/questions/42486650/ocaml-representation-of-values-atoms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!