On Sat, May 23, 2015 at 5:49 PM, Jonathan S. Shapiro <s...@eros-os.org> wrote: > On Wed, May 20, 2015 at 12:24 PM, Matt Oliveri <atma...@gmail.com> wrote: >> Don't you just want something like: >> >> type Node<T> = MetaData * T >> >> type AST = >> ... >> and Expr = >> | MulExpr of Node<Expr> * Node<Expr> > > > More or less, yes. Though it's a bit curious here that Expr is considered a > type where MulExpr is not. One of the conclusions from BitC is that it's > actually useful to allow MulExpr to be a type that can be used and declared.
OK, but I think that's orthogonal to the trick is was pointing out, which was the Node type constructor. > I confess that I don't fully understand the syntax you (and F#) are using > here. Are Expr and AST two independent type declarations that are > co-recursive, or is Expr a subtype of AST here? I'm not sure what this > syntax means, and I'd appreciate a quick explanation. I don't know F#, I was actually trying to imitate your syntax and your example. It can be done in ML too: type 't node = metadata * 't type ast = ... and expr = | MulExpr of expr node * expr node > I think this approach is usefully carried a step further, such that MulExpr > is also a type, and we can then declare a Node<MulExpr>. For Expr there > aren't that many cases to match. For Type ASTs, on the other hand.... Maybe I made a bad assumption about the role of types vs. value constructors in your example. I thought a type roughly corresponds to a nonterminal, and a constructor to a production. So the nonterminals are mutually recursive, and a recurrence that you think of as a child node gets wrapped in Node<_> to attach the common metadata. The whole AST would be a Node<AST>. _______________________________________________ bitc-dev mailing list bitc-dev@coyotos.org http://www.coyotos.org/mailman/listinfo/bitc-dev