私は Ocaml を初めて使用し、再帰データ型で定義された再帰関数のヘルプが必要です。次のようにデータ型を定義しました
type 'a slist = S of 'a sexp list
and
'a sexp = Symbol of 'a | L of 'a slist
私が書いている関数 (subst) は、定義された slist 内のシンボル a をチェックし、それを b に置き換えます。ex subst 1 10 S[ 1; の場合 4; S[L[3; 1;]; 3];] は S[10; を返します。4; S[L[S[3; 10;]]; 3;] . 私のコードは次のとおりです
let rec subst a b sl = match sl with
S s -> match s with
[] -> []
| p :: q -> match p with
Symbol sym -> if sym = a then S[b] :: (**subst** a b S[q]) else
S[p] :: (subst a b S[q])
L l -> (subst a b l) :: (subst a b S[q])
| L lis -> subst a b lis;;
エラーが発生しています:
この関数が適用される引数が多すぎます。「;」を忘れたのかもしれません。
助けてください