
Hi Folks, I am trying to define a data type for this: A Lambda term is one of these: - Variable - Application of a Lambda term to a Lambda term - Abstraction of a Variable in a Lambda term Here's an example of a Lambda term: term = Abstraction (Variable X) (Application (Variable X) (Variable Y)) Is there a way to define Lambda term? Here's an attempt at defining it: data Var = V | W | X | Y | Z data Lambda = Variable Var | Application Lambda Lambda | Abstraction (Variable Var) Lambda But that yields the following error: test.hs:5:71: Not in scope: type constructor or class 'Variable' Any suggestions would be much appreciated. /Roger

Hi Roger,
On 24 November 2011 10:43, Costello, Roger L.
data Var = V | W | X | Y | Z
data Lambda = Variable Var | Application Lambda Lambda | Abstraction (Variable Var) Lambda
Variable is a constructor of the data type Lambda. Abstraction is another. You use Variable as if it was a data type while defining Abstraction. data Lambda = Variable Var | Application Lambda Lambda | Abstraction Lambda Lambda You can use the above declaration to successfully create your example lambda terms. However, it doesn't stop you from constructing things like: Abstraction (Application .. ..) (Variable ..) If you want to go to that land, you either need smart constructors (simpler) or GADTs (more hairy, unfortunately). HTH, Ozgur

On Thu, Nov 24, 2011 at 10:43:58AM +0000, Costello, Roger L. wrote:
Hi Folks,
I am trying to define a data type for this:
A Lambda term is one of these: - Variable - Application of a Lambda term to a Lambda term - Abstraction of a Variable in a Lambda term
Here's an example of a Lambda term:
term = Abstraction (Variable X) (Application (Variable X) (Variable Y))
Is there a way to define Lambda term?
Here's an attempt at defining it:
data Var = V | W | X | Y | Z
data Lambda = Variable Var | Application Lambda Lambda | Abstraction (Variable Var) Lambda
The right way to do it would be data Var = V | W | X | Y | Z data Lambda = Variable Var | Application Lambda Lambda | Abstraction Var Lambda However, I also note that it is a bit strange to use an enumeration type for your variables; what if you need more than five? -Brent
participants (3)
-
Brent Yorgey
-
Costello, Roger L.
-
Ozgur Akgun