purescript-deprecated / purescript-generics

21 stars 20 forks source link

Add showSignature and showDataConstructor #24

Closed hdgarrood closed 8 years ago

hdgarrood commented 8 years ago

Also a Show GenericSignature instance which uses showSignature. This can be very useful for diagnosing issues such as the one mentioned in https://github.com/paf31/purescript-foreign-generic/pull/10

hdgarrood commented 8 years ago

Note that this Show instance isn't entirely faithful, as it pretends that the thunks (Unit -> a) are not there, but it's still very useful IMO. Example output:

SigProd "Test.Main.TupleArray" [ { sigConstructor: "Test.Main.TupleArray", sigValues: [ SigArray (SigProd "Data.Tuple.Tuple" [ { sigConstructor: "Data.Tuple.Tuple", sigValues: [ SigInt, SigString ]} ]) ]} ]
paf31 commented 8 years ago

:+1: Looks good. Do you want to have a go at the parens fix? No worries if not, I can merge this either way.

hdgarrood commented 8 years ago

Oh yeah sure - I guess if sig is a SigProd, SigRecord, or SigArray, then we need parens here, and otherwise we don't?

hdgarrood commented 8 years ago

I had a go at the parens thing. How does this look?

paf31 commented 8 years ago

Looks good, thanks!

I usually break these into two functions, like typeAsBox and typeAtomAsBox in Language.PureScript.Pretty.Types, where "atom" means something that doesn't need to be wrapped in parens. The showsPrec way is to have a family of functions parameterized by an integer argument representing the current precedence level, but we only have two levels here.

Could you please squash commits and ping me, and I'll get this merged in.

hdgarrood commented 8 years ago

Squashed.

paf31 commented 8 years ago

Thanks!

paf31 commented 8 years ago

Released as v0.7.2