Version française
Home     About     Download     Resources     Contact us    
Browse thread
Extracting common information
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Stephen Weeks <sweeks@s...>
Subject: Re: [Caml-list] Extracting common information
> I am working on a simple compiler in Ocaml, and having some difficulty
> settling on the best design for my AST.
...
> then I realized I would want to thread along some annotation to store the
> types, line numbers, and things like that.  Since these annotations will
> change between compiler passes,

I ran in to the same design problem when writing MLton.  My solution was to use
lisp-style property lists, but with appropriate ML static typing.  See

  http://mlton.org/PropertyList

The essence of the solution is to use a dynamically extensible sum type.  Each
tree node holds a list ref of values in the sum type.  Each compiler pass builds
a new variant of the sum type and stores whatever it needs in the list.