[Haskell-cafe] Rank N type tutorial?

Jason Dagit dagit at codersbase.com
Fri Oct 27 19:26:25 EDT 2006


On 10/27/06, David House <dmhouse at gmail.com> wrote:
> On 27/10/06, David House <dmhouse at gmail.com> wrote:
> > heteroList' = [MkT' 5, MkT' (), MkT' True]
> > main = mapM_ print heteroList'
> >
> > {- prints:
> > 5
> > ()
> > True
> > -}
>
> Sorry, the definition of main is a bit off. It should read:
>
> main = mapM_ (\(MkT' x) -> print x) heteroList'
>
> Of course you have to unpack the MkT' first (or define a Show instance
> for T', noting that you can't derive anything on existentials).

So you specified that the types which T' wraps up should be instances
of Show, so to me it makes sense that you should be able to derive
Show in a way similar to how newtype deriving works.  But perhaps
there is a subtlety that I'm missing?

I mean, to make an instance of Show I'm just going to type something
trivial like this:
instance Show T' where
  show (MkT' a) = "MkT' " ++ show a

Or perhaps, since I'm writing it by hand I'd omit the "MkT' " and just
show the a.

thanks,
Jason


More information about the Haskell-Cafe mailing list