我正在學習多態和SML。我有點不確定如何處理元素的總和,同時保持函數多態。 說,如果我有這樣的定義... datatype 'a customList = nothing | customL of 'a * 'a customList
這個列表... val a = customL(2, customL(1, customL(3, nothing)))
我想我需要使用(OP +),因爲多態
type VAR = identifier
type code = instruction list
type environment = identifier list
type EXPR = environment -> code * environment
fun ADD_OP expr expr' env = DUMMY
fun SUB_
如果我嘗試編寫一個參數化模塊,該參數化模塊在參數提供的未指定類型上調用=,SML/NJ將拋出一個類型錯誤。例如,如果我有一個簽名 signature SIG =
sig
type t
end
,並嘗試參數模塊F在模塊S與簽名SIG functor F (S : SIG) =
struct
fun f (x:S.t) (y:S.t) = (x = y)
end
我
我得到了這兩個問題對於這個功能: fun funion([(x:int list,y:bool list)]) =
let
fun join(nil,final) = final |
join(x::xs,final) = join(xs,union(x,final)) |
join(_,final) = final
in
join([(x,y)],(nil,nil))
我試圖在SMLNJ中創建一個curried函數,它將一個(string * bool)對添加到列表中。我可以這樣做: fun push L a b = (a,b) :: L;
-val push = fn : ('a * 'b) list -> 'a -> 'b -> ('a * 'b) list
這一工程,但我想,只有接受(字符串*布爾)列表,字符串和布爾函數。我無法弄清楚如何編寫函數簽名