On Fri, May 15, 2015 at 11:58 AM, Matt Rice <ratm...@gmail.com> wrote: > On Fri, May 15, 2015 at 7:59 AM, Jonathan S. Shapiro <s...@eros-os.org> wrote: >> So I have a "how do I use this idiomatically" sort of question... >> >> In ML/Haskell and friends, there is no syntactically simple way to say "all >> legs of this union have the following fields in common". You either build a >> structure with the common fields and mention it explicitly in every leg of >> the union, or (conversely) you make the union an element of a larger >> structure. >> >> AST nodes are a use case. They tend to have a large number of common >> metadata fields (position, type, auxiliary marker bits of various sorts...) >> and a small variant part describing the children of the node. >> >> Is there a common idiom that people use in cases like this? > > in ML i've always used the latter, where the common elements and the > union are elements of a larger structure
That's what I'd do. You want to factor out the common stuff, even if it's just types, or else you'll feel silly needing to factor out the handling of the common fields in each pattern match. (OTOH, if you know in advance that the way of handling the common fields will actually not be the same across cases, then probably you shouldn't factor the type either. Basically, whatever's convenient.) _______________________________________________ bitc-dev mailing list bitc-dev@coyotos.org http://www.coyotos.org/mailman/listinfo/bitc-dev