Recursive Unions
[Thread Prev] | [Thread Next]
- Subject: Recursive Unions
- From: Yves Cloutier <yves.cloutier@xxxxxxxxx>
- Reply-to: myrddin-dev@xxxxxxxxxxxxxx
- Date: Thu, 16 Aug 2018 17:17:38 -0400
- To: myrddin-dev@xxxxxxxxxxxxxx
Is it possible to have recursive "ADT" a-la-ML using unions? I'm leaning towards no, as I get the following error: syntax error, unexpected Ttick making reference to `Prim (byte[:], `Expression, `Expression) from the code below: use std type Expression = union `Int int `Prim (byte[:], `Expression, `Expression) ;; const eval = { e match e | `Int x: -> x | `Prim ("+", x, y): -> eval(x) + eval(y) | `Prim ("-", x, y): -> eval(x) - eval(y) | `Prim ("*", x, y): -> eval(x) * eval(y) ;; } const main = { var x = eval(`Int 2) std.put("2 = {}", x) var y = eval(`Prim("+", `Int 2, `Int 5)) std.put("2 + 5 = {}", y) }
Re: Recursive Unions | Ori Bernstein <ori@xxxxxxxxxxxxxx> |
- Prev by Date: Re: What IRC network does Myrddin use?
- Next by Date: Re: Recursive Unions
- Previous by thread: Re: What IRC network does Myrddin use?
- Next by thread: Re: Recursive Unions
- Index(es):