GHC wish

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

GHC wish

Christophe Poucet
Dear all,

I recently stumbled upon something that I think should be added to the
GHC wishlist. Not knowing where to put it, I will put it here. As there
is deriving(Show) for most basic data types, wouldn't it be possible to
have something similar but then deriving(Pretty). When printing ASTs it
could make it much easier to look at the output.

With regards,
Christophe

--
Christophe Poucet
Ph.D. Student
Phone:+32 16 28 87 20
E-mail: Christophe (dot) Poucet (at) imec (dot) be
Website: http://notvincenz.com/ 
IMEC vzw – Register of Legal Entities Leuven VAT BE 0425.260.668 – Kapeldreef 75, B-3001 Leuven, Belgium – www.imec.be
*****DISCLAIMER*****
This e-mail and/or its attachments may contain confidential information. It is intended solely for the intended addressee(s).
Any use of the information contained herein by other persons is prohibited. IMEC vzw does not accept any liability for the contents of this e-mail and/or its attachments.
**********

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

Re: GHC wish

Jared Updike
Sorry, meant to reply all:
---------------------------------------------------

This tool (DrIFT) can derive these instances for you, if you care to
make rules for it, for Pretty:

   http://repetae.net/john/computer/haskell/DrIFT/

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

Re: GHC wish

Christophe Poucet
In reply to this post by Christophe Poucet
Hello Chris,

It seems that your reply only replied to me and not to the haskell-cafe
list.  I hope you do not mind that I reply to the list.  Anyways,
regarding how the AST is pretty printed.  I was not thinking of any
highlevel pretty printing of an AST (at least not derived
automatically).  The type of pretty printing I was thinking of would be
synonymous to what deriving Show would give you for any type, except
that it would be layed out a bit more cleanly with indentation and newlines.
Here is an example:

data Foo = Foo {unFoo :: [Bar]}
data Bar = Bar {unBar :: Int}

prettyPrint . Foo. map Bar $ [1..10]
Foo {
  unFoo = [
    Bar {unBar = 1},
    Bar {unBar = 2},
    ..
    Bar {unBar =10}
    ]
}

Jared:  Thank you for mentioning DrIFT.  Will certainly take a look at it :)

Cheers,
Christophe

Christopher Brown wrote:

> Christophe,
>
> But that depends on what you think is the correct way of displaying  
> an AST. I can personally think of a few ways an AST could be pretty  
> printed.
>
> Chris.
>
>
> On 24 May 2006, at 00:05, Christophe Poucet wrote:
>
>> Dear all,
>>
>> I recently stumbled upon something that I think should be added to  
>> the GHC wishlist. Not knowing where to put it, I will put it here.  
>> As there is deriving(Show) for most basic data types, wouldn't it  be
>> possible to have something similar but then deriving(Pretty).  When
>> printing ASTs it could make it much easier to look at the output.
>>
>> With regards,
>> Christophe
>>
>> --
>> Christophe Poucet
>> Ph.D. Student
>> Phone:+32 16 28 87 20
>> E-mail: Christophe (dot) Poucet (at) imec (dot) be
>> Website: http://notvincenz.com/  IMEC vzw – Register of Legal  
>> Entities Leuven VAT BE 0425.260.668 – Kapeldreef 75, B-3001 Leuven,  
>> Belgium – www.imec.be
>> *****DISCLAIMER*****
>> This e-mail and/or its attachments may contain confidential  
>> information. It is intended solely for the intended addressee(s).
>> Any use of the information contained herein by other persons is  
>> prohibited. IMEC vzw does not accept any liability for the contents  
>> of this e-mail and/or its attachments.
>> **********
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> [hidden email]
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
>


--
Christophe Poucet
Ph.D. Student
Phone:+32 16 28 87 20
E-mail: Christophe (dot) Poucet (at) imec (dot) be
Website: http://notvincenz.com/ 
IMEC vzw – Register of Legal Entities Leuven VAT BE 0425.260.668 – Kapeldreef 75, B-3001 Leuven, Belgium – www.imec.be
*****DISCLAIMER*****
This e-mail and/or its attachments may contain confidential information. It is intended solely for the intended addressee(s).
Any use of the information contained herein by other persons is prohibited. IMEC vzw does not accept any liability for the contents of this e-mail and/or its attachments.
**********

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

Re: GHC wish

Bulat Ziganshin-2
In reply to this post by Christophe Poucet
Hello Christophe,

Wednesday, May 24, 2006, 3:05:53 AM, you wrote:
> I recently stumbled upon something that I think should be added to the
> GHC wishlist. Not knowing where to put it, I will put it here. As there
> is deriving(Show) for most basic data types, wouldn't it be possible to
> have something similar but then deriving(Pretty). When printing ASTs it
> could make it much easier to look at the output.

believe you or not, but that is a pretty standard technique
called generic programming. i've seen 7 tools to do it (including
DrIFT) and moreover, 3 of them are included in GHC.

one of these GHC-bundled tools is Template Haskell. you can see it's
description at
http://haskell.org/hawiki/TemplateHaskell
http://haskell.org/hawiki/TemplateHaskellTutorial
http://freearc.narod.ru/th.htm
http://freearc.narod.ru/thdoc.htm

my library http://freearc.narod.ru/Streams.tar.gz contains module
Data/AltBinary/TH.hs that you can use as the starting point - it
derives instances for Binary class. File "Examples/AltBinary/DeriveBinary.hs"
contains example of it's usage. use "-ddump-splices" GHC option when
compiling example to see actual code generated

i also attached here simple module that generates "Show" instances using TH

and last - in my feeling, DrIFT is simpler to use, TH is really
head-breaking thing. on the other side, by using TH you will not rely
on any external tools and special preprocessing. on the third side ;)
TH works only with GHC while DrIFT is compatible with any Haskell
compiler. decision is up to you

anyway, please share your code - it is rather common task and i wonder
why noone still implemented this


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

derive.hs (2K) Download Attachment
derive-test.hs (240 bytes) Download Attachment