子类型作为SML数据类型的子集
我对Okasaki关于纯功能数据结构的书不满意的几件事之一是,他的代码充满了不尽详尽的模式匹配。举例来说,我将为他提供实时队列的实现(重构为消除不必要的挂起): infixr 5 ::: datatype 'a stream = Nil | ::: of 'a * 'a stream lazy structure RealTimeQueue :> QUEUE = struct (* front stream, rear list, schedule stream *) type 'a queue = 'a stream * 'a list * 'a stream (* the front stream is one element …