Haskell type declaration summary

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

Haskell type declaration summary

Andrew Butterfield-2
Dear Haskellers,
 any quick and easy way to extract all the type declarations from a Haskell source file?
(for easy reference)

Regards,

Andrew Butterfield
School of Computer Science & Statistics
Trinity College
Dublin 2, Ireland

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Haskell type declaration summary

Andrew Butterfield-2
Hi Kevin,
 yes - I can do that, but it is tedious to issue each command, and I may not remember what all the types are called
(I know that :browse will tell me what things exist in the current module with a capital letter)

Also I want to be able to do this for a file different to the one currently loaded in GHCi.

Something along the lines of (assuming a unix shell):

$> showtypes MyBigMonsterHaskellFile.hs
data X = A | B
type Name = String
newtype Y = Z Name
....
$>

(maybe with a blank line for each one..)
Has no-one rustled up something like this - or do I need to look into Haskell parsing...?

Cheers, Andrew

> On 4 May 2017, at 16:30, Kevin Quick <[hidden email]> wrote:
>
>
> You can use ghci's browse:
>
> $ ghci
> Prelude> import Data.Maybe
> Prelude Data.Maybe> :browse Data.Maybe
> ...
> Prelude Data.Maybe> :l MyFile.hs
> MyFile Data.Maybe> :browse MyFile
> ...
>
> Andrew Butterfield writes:
>
>> Dear Haskellers,
>> any quick and easy way to extract all the type declarations from a Haskell source file?
>> (for easy reference)
>>
>> Regards,
>>
>> Andrew Butterfield
>> School of Computer Science & Statistics
>> Trinity College
>> Dublin 2, Ireland
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
>

Andrew Butterfield
School of Computer Science & Statistics
Trinity College
Dublin 2, Ireland

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Haskell type declaration summary

Brandon Allbery
In reply to this post by Andrew Butterfield-2
From source you'd be looking at using haskell-src-exts. Alternately:

- echo :browse | ghci foo.hs

- compile it, dump the .hi file (ghc --show-iface foo.hi) likely with postprocessing to only show the types

On Thu, May 4, 2017 at 3:30 AM, Andrew Butterfield <[hidden email]> wrote:
Dear Haskellers,
 any quick and easy way to extract all the type declarations from a Haskell source file?
(for easy reference)

Regards,

Andrew Butterfield
School of Computer Science & Statistics
Trinity College
Dublin 2, Ireland

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.



--
brandon s allbery kf8nh                               sine nomine associates
[hidden email]                                  [hidden email]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Haskell type declaration summary

Andrew Butterfield-2
Dear Brandon,
 thanks for that - the echo :browse solution is ideal because I can easily write a short Haskell program
to filter out the type declarations from the output.
In fact it becomes easy to extract other kinds of declarations as well.

Here the offside rule really is my friend.

I'll post a fully worked solution once I build it.

Thanks, Andrew

On 4 May 2017, at 17:22, Brandon Allbery <[hidden email]> wrote:

From source you'd be looking at using haskell-src-exts. Alternately:

- echo :browse | ghci foo.hs

- compile it, dump the .hi file (ghc --show-iface foo.hi) likely with postprocessing to only show the types

On Thu, May 4, 2017 at 3:30 AM, Andrew Butterfield <[hidden email]> wrote:
Dear Haskellers,
 any quick and easy way to extract all the type declarations from a Haskell source file?
(for easy reference)

Regards,

Andrew Butterfield
School of Computer Science & Statistics
Trinity College
Dublin 2, Ireland

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.



--
brandon s allbery kf8nh                               sine nomine associates
[hidden email]                                  [hidden email]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net

Andrew Butterfield
School of Computer Science & Statistics
Trinity College
Dublin 2, Ireland


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Haskell type declaration summary

MarLinn
In reply to this post by Brandon Allbery

echo :browse | ghci foo.hs

And don't forget you can also do (in ghci)

    :! echo :browse | ghci foo.hs

And, while you're at it:

    :def browseOther \file -> pure $ ":! echo :browse | ghci \"" ++ file ++ "\""

Endless fun.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.