1
我翻譯的小Mler的功能,在這個數據類型問題寫在F#相互遞歸函數
type sexp<'T> =
An_Atom of 'T
| A_slist of slist<'T>
and
slist<'T> =
Empty
| Scons of sexp<'T> * slist<'T>
功能操作
// occurs_in_slist : aVal slist -> int
// checks the number of occurrence for aVal in slist
let rec occurs_in_slist =
function
_, Empty-> 0
| (aVal : 'T), Scons(aSexp, (aSlist : 'T)) ->
occurs_in_sexp (aVal, aSexp) + occurs_in_slist (aVal, aSlist)
and
aVal, An_Atom (bVal) -> if (aVal = bVal) then 1 else 0
| (aVal , A_slist(aSlist)) -> occurs_in_slist (aval, aSlist)
不過,我得到這個錯誤的第二個功能
error FS0010: Unexpected symbol '->' in binding. Expected '=' or other token.
這是一個衛生署!時刻。謝謝。 – unj2