错误:未绑定类型构造函数:TypeInteger

问题描述 投票:0回答:1
(* Define a datatype for representing variables as strings *)
datatype Variable = GLL_Variable of string;

(* Define a datatype for variable types (boolean or integer) *)
datatype Type = TypeBoolean | TypeInteger;

(* Create a variable 'num' with the name "num" and type TypeInteger *)
val num = GLL_Variable("num");
val declaringNum = (num, TypeInteger);

(* Define a datatype for internal types: InternalNoType, InternalTypeInteger, and InternalTypeBoolean *)
datatype InternalType = InternalNoType | InternalTypeInteger | InternalTypeBoolean;

(* Define a type alias for a function mapping variables to their internal types *)
type TypeMapTable = (Variable -> InternalType);

(* Define a function 'changeTypeMapTable' that takes a TypeMapTable 'x', 
   a Variable 'a' with type TypeInteger, and a Variable 'y'. It checks 
   if 'y' is equal to 'a'. If yes, it returns InternalTypeInteger, 
   otherwise, it queries the 'TypeMapTable' 'x' to determine the type. *)
val changeTypeMapTable =
    fn (x: TypeMapTable) =>
        fn (a: Variable, b: TypeInteger) =>
            fn (y: Variable) =>
                if y = a then
                    InternalTypeInteger
                else
                    x(y);

总之,这段代码定义了一组数据类型和一个函数来处理变量的类型映射,特别是在“changeTypeMapTable”的帮助下检查它们是否是整数类型。

但是在编译代码时,我收到错误 Error: unbound type constructor: TypeInteger

sml smlnj
1个回答
0
投票

您的问题出现在以下声明中。在此之前一切都很好。

val changeTypeMapTable =
    fn (x: TypeMapTable) =>
        fn (a: Variable, b: TypeInteger) =>
            fn (y: Variable) =>
                if y = a then
                    InternalTypeInteger
                else
                    x(y);

您已使用构造函数

TypeInteger
作为
b: TypeInteger
中的类型名。虽然我不确定您的代码是否真正有意义,但在语法上编写是有效的:
b: Type

请注意,

b
实际上从未被使用过。

© www.soinside.com 2019 - 2024. All rights reserved.