Sml 作为中缀从结构导出的标准ML运算符

Sml 作为中缀从结构导出的标准ML运算符,sml,polyml,Sml,Polyml,我想在结构a中声明一个中缀运算符,以便在结构外部使用。但我似乎无法在结构外部识别出“infixness”,即使结构已经打开。以下是使用Poly/ML的示例: > structure A = struct infix 6 ++ fun a ++ b = a + b end; structure A: sig val ++: int * int -> int end > 1 A.++ 2; poly: : error: Type error in function applicat

我想在结构a中声明一个中缀运算符,以便在结构外部使用。但我似乎无法在结构外部识别出“infixness”,即使结构已经打开。以下是使用Poly/ML的示例:

> structure A = struct infix 6 ++ fun a ++ b = a + b end;
structure A: sig val ++: int * int -> int end
> 1 A.++ 2;
poly: : error: Type error in function application.
   Function: 1 : int
   Argument: A.++ : int * int -> int
   Reason: Value being applied does not have a function type
Found near 1 A.++ 2
Static Errors
> let open A in 1 ++ 2 end;
poly: : error: Type error in function application.
   Function: 1 : int
   Argument: ++ : int * int -> int
   Reason: Value being applied does not have a function type
Found near let open A in 1 ++ 2 end
Static Errors

这是标准ML的限制吗?

是的,标准ML不支持这一点。每次
打开该结构时,您都必须重新声明固定性和优先级(可选)。解决这个问题的一种方法是全局声明固定性,也就是说,在任何结构之外,但是单独的编译都不能很好地支持这一点,而且它也不是非常模块化的。您可以阅读有关它的更多信息,以及有关的可能解决方法

对于我自己的项目,我在我的文本编辑器中定义了一个快捷方式,它将扩展为
open
声明和fixity声明

另外,作为个人风格指南,我不宣布优先顺序。如果我需要将多个中缀运算符混合到同一个表达式中,我宁愿显式使用括号。将标识符解析为中缀很容易,但解析优先级却不容易