值的Ocaml表示-原子 [英] Ocaml representation of values - Atoms

查看:85
本文介绍了值的Ocaml表示-原子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了一些OCaml值的内部表示.空数组的表示形式是atom(0),即具有tag=0size=0的块.空的浮点数组也用atom(0)表示.

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.

是否存在用tag > 0的原子表示的OCaml值?如果不是:OCaml字节码集出于什么目的包含ATOM n指令?

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?

推荐答案

标记> 0用于带有参数的构造函数,这会使它们不是原子.另一方面,不带参数的构造函数存储为int而不是块,因此也不存储原子.因此,我认为不使用atom(0).除了...

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

似乎不允许空记录.除了直接创建这样的块,我想不出另一种方法来创建带有标签的0大小的块.但这不会使用ATOM指令.

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.

这篇关于值的Ocaml表示-原子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆