0

我在网上遇到了这个我觉得很有趣的问题,它有一个不错的解释,但我对解决方案感到困惑。所以给定

type 'a fenv = name -> 'a 

创建一个类型的值

'a fenv

这将是我们的空环境。我认为这是以下内容

exception NotFound of name
val empty = fn name => raise NotFound name

它可能会返回 Notfound 名称异常,但我可能做错了,因为我继续得到

Type clash: expression of type
   'a alist -> 'a alist alist
cannot have type
   'a alist alist
Toplevel input:
val (_: 'a fenv) = empty
Unbound type constructor: fenv

抱歉,如果这在 sml 仍然很简单,有人可以解释我将如何获得解决方案吗?

谢谢

4

1 回答 1

1

如何创建一个由函数表示的空环境

你可以这样做:

type name = string
exception NotFound of name
fun empty name = raise NotFound name

我可能做错了,因为我继续得到

Type clash: expression of type
   'a alist -> 'a alist alist
cannot have type
   'a alist alist

你确实意识到你的代码没有提到'alist,对吧?您可能正在使用具有过时定义的 REPL type 'a fenv,或者您的文件包含多个定义,一个涉及 this 'a alist,另一个包含此'a fenv

于 2018-03-08T10:55:30.247 回答