在utop
(或dune utop
)中加载代码并打印任何数据构造函数Bin.Stop
时,#show Bin.Stop;;
我遇到了崩溃。
utop # #show Bin.Stop;;
>> Fatal error: Ident.rename Bin.nat
Fatal error: exception Misc.Fatal_error
~ via v4.12.0 took 4m41s
❯
虽然ocaml
不会崩溃。这是一个错误还是有明显的理由为什么这是非法的?
(* SOTypeLevelNat.ml *)
module Bin : sig
type stop = Qasdpaokdsap
type 'a zero = Sasddkasdo
type 'a one = Zoldjsfoij
type _ nat =
| Stop : 'stop nat
| Times2 : 'n nat -> 'n zero nat
| Times2Plus1 : 'n nat -> 'n one nat
end = struct
type stop = Qasdpaokdsap
type 'a zero = Sasddkasdo
type 'a one = Zoldjsfoij
type _ nat =
| Stop : 'stop nat
| Times2 : 'n nat -> 'n zero nat
| Times2Plus1 : 'n nat -> 'n one nat
end
utop # #use "SOTypeLevelNat.ml";;
module Peano :
sig
type 'a s = S
type z = Z
type 'n nat = Zero : 'a nat | Succ : 'n nat -> 'n s nat
end
module Bin :
sig
type stop = Qasdpaokdsap
type 'a zero = Sasddkasdo
type 'a one = Zoldjsfoij
type _ nat =
Stop : 'stop nat
| Times2 : 'n nat -> 'n zero nat
| Times2Plus1 : 'n nat -> 'n one nat
end
打印一个类型,比如说,nat
效果很好
utop # #show Bin.nat;;
type nonrec _ nat =
Stop : 'stop Bin.nat
| Times2 : 'n Bin.nat -> 'n Bin.zero Bin.nat
| Times2Plus1 : 'n Bin.nat -> 'n Bin.one Bin.nat