I have googled about trying to find a simple example of Haskell being used to define a simple language but to no avail.
I did find this post on stackoverflow giving a similar example, but when i implemented it, it didn’t appear to work:
Haskell – How to best to represent a programming language's grammar?
an example expression in this language would be:
if true then x else (if false then y else true) Your Haskell data type
would look something like this:
data Expr = Var String
| Lit Bool
| If Expr Expr Expr
however, when i entered if true then x else (if false then y else true) into the console as input, it complained about “x” not being interpretable. It also didn’t like true and false.
EDIT: I did derive “show” also, at the end
If you want to represent
if true then x else (if false then y else true)in your little language, you need to use the following expression:If, as you say, you derived
Showthis will also show exactly as entered.I’m not sure what more you want to do! Possible further things to try are:
Showinstance to get the printed representation to look nicer.