Reputation: 19
I want to extend a type ExprTree
(expression tree) with a new constructor App
that takes in a string and a list as arguments. Below is the type ExprTree
:
type ExprTree =
| Const of int
| Ident of string
| Sum of ExprTree * ExprTree
| Let of string * ExprTree * ExprTree
Upvotes: 0
Views: 62
Reputation: 243051
The definition that you posted in a comment is correct. Your version from the comments was:
type ExprTree =
| Const of int
| Ident of string
| Sum of ExprTree * ExprTree
| Let of string * ExprTree * ExprTree
| App of string * ((ExprTree) list)
The definition of the App
constructor has some unnecessary parentheses - you do not need any and can write just string * ExprTree list
, but they do not hurt eihter. I suspect that the issue was not with the definition, but with how you use the constructor. The following is the right syntax:
App("foo", [Const 1; Ident "x"])
Upvotes: 1