[Haskell-cafe] How to check if two Haskell files are the same?

Chaddaï Fouché chaddai.fouche at gmail.com
Wed Sep 17 17:23:21 EDT 2008

2008/9/16 Mauricio <briqueabraque at yahoo.com>:
> Hi,
> I would like to write a Haskell pretty-printer,
> using standard libraries for that. How can I
> check if the original and the pretty-printed
> versions are the same? For instance, is there
> a file generated by GHC at the compilation
> pipe that is always guaranteed to have the
> same MD5 hash when it comes from equivalent
> source?

There is not, though I have a suggestion :
Am I correct in assuming that you mean "equivalent source" in the
sense that only the formatting (and eventually {;} as a layout format
consequence) differs ?

Then the sequence of tokens from the source ought to do the trick as
long as you delete location information (map unLoc) and transform
ITvocurly ("virtual" braces for layout induced blocks) into ITocurly
(real braces for no-layout blocks) (and same for ITvccurly) (it's just
another map). If only the formatting differs, those two should be

Now the current GHC don't give you direct access to the Token stream
but the next release should contain the functions I wrote to support
this (for HaRe).

In fact you could do this with the AST but it would be more
complicated to do the necessary extractions and comparisons...


More information about the Haskell-Cafe mailing list