Some reading problem


Hi everybody,

I’m new to Haskell, and i don’t really know how to read that part of a code i found :

data E = Var String
| App E E
| Abs String E
deriving (Eq, Show)

Thanks a lot !


This code is saying there is a data type called E (that is the type). That type has three ways of constructing it: Var :: String -> E, App :: E -> E -> E and Abs :: String -> E -> E. Using those constructors you can make an abstract syntax tree, for example:

example1 = App (Abs "x" (Var "x")) (Var "y") :: E

In this case the type E probably stands for lambda calculus Expression. Are you familiar with the lambda calculus? Then the example I gave above stands for the application of the identity function to the unbound variable y.

The last line deriving (Eq, Show) asks the compiler to automatically derive instances of the Eq type class, which means that the functions (==) and (!=) can be used on this data type, and the Show type class, which means that the show function can be used on this data type.


Thanks for the answer, I’m not really familiar with the lambda calculus but i’m learning it :slight_smile:


By the way, these are called algebraic data types if you want to search for them. The Haskell wiki also has a page for them:


I’ve got a program that parses lambda-calculus, I think can I contact you somewhere so you can help me understanding it ?