相关疑难解决方法(0)

标准ML仿函数示例

标准ML中的函数与模块系统相关,并且可以基于其他结构生成结构.下面给出了为各种类型的列表生成列表组合器的仿函数的示例,但是此示例存在一个问题:

各种类型的列表都具有优势 - 例如,惰性列表可以无限长,并且concantenation列表具有O(1)concat运算符.但是当所有这些列表类型符合相同的签名时,仿函数只能使用它们的常规属性.

因此,我的问题是:什么是一个很好的例子,当函子有用时,各种生成的结构不会失去它们的特殊能力?

signature MYLIST =
sig
  type 'a t
  val null : 'a t -> bool
  val empty : 'a t
  val cons : 'a * 'a t -> 'a t
  val hd : 'a t -> 'a
  val tl : 'a t -> 'a t
end

structure RegularList : MYLIST =
struct
  type 'a t = 'a list
  val null = List.null
  val empty = []
  val cons = op::
  val hd = List.hd
  val tl …
Run Code Online (Sandbox Code Playgroud)

functional-programming ml sml functor

10
推荐指数
1
解决办法
5112
查看次数

标签 统计

functional-programming ×1

functor ×1

ml ×1

sml ×1