lambda calculus - Haskell AST with recursive types -


i'm trying build lambda calculus solver, , i'm having slight problem constructing ast. lambda calculus term inductively defined as:

1) variable

2) lambda, variable, dot, , lambda expression.

3) bracket, lambda expression, lambda expression , bracket.

what (and @ first tried) this:

data expr =      variable   | abstract variable expr   | application expr expr 

now doesn't work, since variable not type, , abstract variable expr expects types. hacky solution have:

type variable = string  data expr =      atomic variable   | abstract variable expr   | application expr expr 

now annoying since don't atomic variable on own, abstract taking string rather expr. there way can make more elegant, , first solution?

your first solution erroneous definition without meaning. variable not type there, it's nullary value constructor. can't refer variable in type definition can't refer value, true, false or 100.

the second solution in fact direct translation of write in bnf:

var  ::= <string> term ::= λ <var>. <term> | <term> <term> | <var> 

and there nothing wrong it.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -