Module extractor
Simon Marlow
simonmar@microsoft.com
Thu, 1 Feb 2001 08:45:35 -0800
Jan writes:
> The parser aims to extract this information from the source
> files:
>
> data Module = Module
> { name :: String -- done
> , comment :: String -- done
> , exports :: [Export] -- chunk for now
> , imports :: [Import] -- chunk for now
> , fixities :: [Fixity] -- done
> , classes :: [Class] -- chunk for now
> , instances :: [Instance] -- chunk for now
> . categories :: [String] -- chunk for now
> , functions :: [Function] -- done
> , footnote :: String -- done
> }
A small comment which might be helpful in the future: It looks like
what you're doing could be formulated as an extension of the Haskell
abstract syntax. This reminds me that Tim Sheard has a nice way of
factoring data types to make them extensible, and to allow
mostly-generic passes over the structure to be written without
duplicating a lot of code.
very briefly, the idea goes like this: if you have a data type
data T = A T | B T
then you can abstract it, like this:
data T a = A a | B a
and define a "knot-tyer":
data MyT = MyT (T MyT)
this lets you extend the type without modifying T:
data MyT = OldT (T MyT)
| NewT ...
Tim implemented his ideas in the Haskell abstract syntax and parser
distributed with GHC (fptools/hslibs/hssource), and I'd really like to
fold his changes back in - if he ever gets round to sending me the code
:) For example, this would be a really neat way to add GHC extensions
and HaskellDoc extensions to the existing Haskell parser.
Cheers,
Simon