我是初學者,我使用的術語可能不準確。OCaml:使用匹配和類型鑄造
我
type t = True | False | If of t * t * t | Int of int | Plus of t * t | GT of t * t
let isval t =
match t with
True|False -> true
| Int _ -> true
| _ -> false
我想實現一個eval函數。
let rec step t =
match isval t with
true -> raise NormalForm
| false -> match t with
If(t1, t2, t3) when t1=True -> t2
| If(t1, t2, t3) when t1=False -> t3
| Plus(t1, t2) -> t1+t2
| GT(t1, t2) -> t1>t2
| _ -> raise NormalForm;;
錯誤發生在Plus(t1, t2) -> t1+t2
,稱「這個表達式的類型爲t,但預計int類型的表達」。
什麼問題?我應該如何解決它?