次の型の値があり、それらの型に基づいて計算を実行したいのですが、次のようなエラーが発生しました。
この式には型の値がありますが、型intの式が必要でした
では、計算を行うにはどうすればよいですか?
type binop =
| Plus
| Minus
| Mul
| Div
| Eq
| Ne
| Lt
| Le
| And
| Or
| Cons
type expr =
| Const of int
| True
| False
| NilExpr
| Var of string
| Bin of expr * binop * expr
| If of expr * expr * expr
| Let of string * expr * expr
| App of expr * expr
| Fun of string * expr
| Letrec of string * expr * expr
type value =
| Int of int
| Bool of bool
| Closure of env * string option * string * expr
| Nil
| Pair of value * value
val x : value = Int 1
val x : value = Int 1
私がこれをするとき
x+x;;
それからそれはそのエラーを投げます、そして私はこのようなものが欲しいです:
Nano.value = Int 2
このようなものを修正するとvalue = Int
、何かが返されますが、何かが必要ですNano.value = Int
。Nano.mlというファイルが必要なので、Nano.value
let add (x,y) = match (x,y) with
| (Int xx, Int yy) -> Int (xx + yy)
| ( _ , _) -> Int 0