How to check if two Haskell files are the same?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

How to check if two Haskell files are the same?

Maurí­cio
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?

Thanks,
Maurício

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: How to check if two Haskell files are the same?

Antoine Latter-2
On Tue, Sep 16, 2008 at 9:30 AM, Mauricio <[hidden email]> wrote:

> 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?

I don't know the answers to your question, but if you're looking for
inspiration on your project you should check out the following two
packages:

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/haskell-src
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/haskell-src-exts

-Antoine
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: How to check if two Haskell files are the same?

Brandon S Allbery KF8NH
In reply to this post by Maurí­cio
On 2008 Sep 16, at 10:30, Mauricio wrote:
> 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?

Compare .hi files?

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [hidden email]
system administrator [openafs,heimdal,too many hats] [hidden email]
electrical and computer engineering, carnegie mellon university    KF8NH


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: How to check if two Haskell files are the same?

pweaver
In reply to this post by Maurí­cio


On Tue, Sep 16, 2008 at 7:30 AM, Mauricio <[hidden email]> wrote:
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?

I don't know, but you can parse the resulting concrete syntax and compare the original abstract syntax to the new abstract syntax.
 

Thanks,
Maurício

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: How to check if two Haskell files are the same?

John Van Enk
In reply to this post by Maurí­cio
Before you reinvent the wheel, have you looked at Language.Haskell.Pretty?

http://haskell.org/ghc/docs/latest/html/libraries/haskell-src/Language-Haskell-Pretty.html

On Tue, Sep 16, 2008 at 10:30 AM, Mauricio <[hidden email]> wrote:
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?

Thanks,
Maurício

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe



--
/jve

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: How to check if two Haskell files are the same?

Maurí­cio
In reply to this post by Brandon S Allbery KF8NH
>> 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?
>
> Compare .hi files?
>

That was my first thought, but can I be sure
.hi files are going to be exactly the same,
i.e., isn't there some kind of information
(timestamps?) that can change without changes
in the code?

Maurício

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Re: How to check if two Haskell files are the same?

Svein Ove Aas
On Wed, Sep 17, 2008 at 7:04 PM, Mauricio <[hidden email]> wrote:

>>> 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?
>>
>> Compare .hi files?
>>
>
> That was my first thought, but can I be sure
> .hi files are going to be exactly the same,
> i.e., isn't there some kind of information
> (timestamps?) that can change without changes
> in the code?
>
For that matter, the code can change without the .hi file doing so,
eg. if a pragma noinline'd function is altered without changing its
type/strictness - or a function the optimizer decides is just
pointless to try inlining, for all I know.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: How to check if two Haskell files are the same?

Bugzilla from alfonso.acosta@gmail.com
In reply to this post by Brandon S Allbery KF8NH
On Wed, Sep 17, 2008 at 1:03 AM, Brandon S. Allbery KF8NH
<[hidden email]> wrote:

> On 2008 Sep 16, at 10:30, Mauricio wrote:
>>
>> 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?
>
> Compare .hi files?

You an also compare the resulting object files
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: How to check if two Haskell files are the same?

Brandon S Allbery KF8NH
On 2008 Sep 17, at 14:17, Alfonso Acosta wrote:

> On Wed, Sep 17, 2008 at 1:03 AM, Brandon S. Allbery KF8NH
> <[hidden email]> wrote:
>> On 2008 Sep 16, at 10:30, Mauricio wrote:
>>>
>>> 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?
>>
>> Compare .hi files?
>
> You an also compare the resulting object files


On ELF systems (the majority) you have to watch out for the timestamp  
in the ELF header.  I know there is code in the gcc source that does  
object comparisons to verify that stage3 builds match stage2, omitting  
the header.

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [hidden email]
system administrator [openafs,heimdal,too many hats] [hidden email]
electrical and computer engineering, carnegie mellon university    KF8NH


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: How to check if two Haskell files are the same?

Chaddaï Fouché
In reply to this post by Maurí­cio
2008/9/16 Mauricio <[hidden email]>:

> 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
identical.

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...

--
Jedaï
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: How to check if two Haskell files are the same?

Maurí­cio


Chaddaï Fouché a écrit :

> 2008/9/16 Mauricio <[hidden email]>:
>> 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 ?

Exactly! And with comments removed, since the last
time I checked Language.Haskell.* used not to preserve
that.

>
> 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
> identical.

Good idea. I think that's all that I need. I can write a
hash function that filters and transforms like that.

Thanks,
Maurício

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe