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

时间:2018-03-08 05:48:02

标签: sml ml mosml

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

type 'a fenv = name -> 'a 

创建类型

的值
'a fenv

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

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的新人可以解释一下如何获得解决方案吗?

由于

1 个答案:

答案 0 :(得分: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 ,对吗?您可能要么使用对type 'a fenv有过时定义的REPL,要么您的文件包含多个定义,一个涉及此'alist ,另一个包含此'a fenv