2014-10-27 17 views
0

IM嗨嘗試使用標準庫來寫一個簡單的函數SOME([])解釋爲「Z - >」 Z選項而不是「Z列表選項

應採取以下參數

try = fn: 'a -> 'b list option 
a_list = 'a list 

,並把定義如下:

fun all_answers try a_list = 
    let fun acc(SOME(a), SOME(b)) = SOME([email protected]) 
     | acc(_,_)    = NONE 
    in 
    List.foldl (fn(x,y) => acc(try(x), y)) SOME([]) a_list 
    end 

,我也得到了以下錯誤:

hw3provided.sml:70.3-70.60 Error: operator and operand don't agree [tycon mismatch] 
    operator domain: 'Z list option 
    operand:   'Y -> 'Y option 
    in expression: 
    (List.foldl (fn (<pat>,<pat>) => acc <exp>)) SOME 
C:\Program Files (x86)\SMLNJ\\bin\.run\run.x86-win32.exe: Fatal error -- Uncaught exception Error   with 0 
raised at ../compiler/TopLevel/interact/evalloop.sml:66.19-66.27 

香港專業教育學院試圖分解的功能和錯誤似乎對應於使用一些([]),如果我使用NONE而是typechecks完美

我在這裏總損失

只是櫃面其顯著即時通訊使用的崇高REPL運行腳本

回答

0

想出瞭解決方案,但沒有真正的問題

與括號內的一些([])(SOME([]))

只是爲了防止其他人遇到相同的問題

+0

雖然''(SOME [])'會更習慣(因此對大多數人來說更易讀),您不需要'[]'的括號。 – molbdnilo 2014-10-30 12:51:30