嗨,我需要帮助了解为什么我在此代码中遇到值限制错误,以及如果可能的话如何解决它。
特别是在 val cnil 中,我试图创建一个空的 CLIST 结构来匹配签名,但我不断收到这个值限制错误。
谢谢你的帮助
structure Clist : CLIST =
struct
open CML
datatype 'a request = CONS of 'a | HEAD
datatype 'a clist = CLIST of { reqCh : 'a request chan, replyCh : 'a chan }
(* create a clist *)
val cnil =
let
val reqCh = channel()
val replyCh = channel()
fun loop l = case recv reqCh of
CONS x =>
(loop (x::l))
|
HEAD => (let fun head (h::t) = h | head [] = Empty in send(replyCh, head(l)) end ; loop l)
in
spawn(fn () => loop nil);
CLIST {reqCh = channel(), replyCh = channel() }
end
fun cons x (CLIST {reqCh, replyCh})=
(send (reqCh, CONS x); CLIST {reqCh = reqCh, replyCh = replyCh})
fun hd (CLIST {reqCh, replyCh}) = (send (reqCh, HEAD); recv replyCh)
end
这是签名文件
signature CLIST =
sig
type 'a clist
val cnil : 'a clist
val cons : 'a -> 'a clist -> 'a clist
val hd : 'a clist -> 'a
end
这是我得到的错误:
clist.sml:10.7-22.5 Warning: type vars not generalized because of
value restriction are instantiated to dummy types (X1,X2,...)
clist.sml:1.1-29.4 Error: value type in structure doesn't match signature spec
name: cnil
spec: 'a ?.Clist.clist
actual: ?.X1 ?.Clist.clist