[Haskell-cafe] Deriving Show for non-regular data types
adam vogt
vogt.adam at gmail.com
Thu Mar 12 13:52:24 UTC 2015
Hi Mark,
Adding this instance lets your example work:
instance Show1 BankersDeque where showsPrec1 = showsPrec
Regards,
Adam
On Thu, Mar 12, 2015 at 9:36 AM, Mark Laws <mdl at 60hz.org> wrote:
> On Thu, Mar 12, 2015 at 12:25 PM, adam vogt <vogt.adam at gmail.com> wrote:
> > This combination seems to work:
> >
> > instance (Show a, Show1 d) => Show (d a) where
> > showsPrec = showsPrec1
> >
> > deriving instance (Show (d a), Show1 d)
> > => Show (SimpleCatDeque d a)
> >
> > But it needs overlapping instances. I don't see another way to express
> >
> > (Show (d a), Show (d (d a)), Show (d (d (d a))), ... )
> >
> > in a way that ghc will lazily evaluate the ...
>
> Hi Adam and David,
>
> Thanks for the tips. This works, but there's another issue now:
>
> > :load SimpleCatenableDeque.hs BankersDeque.hs
> > import BankersDeque
> > cons 1 (cons 2 empty ++ (cons 3 (cons 7 (cons 123 empty)))) ++ (cons 4
> (cons 5 (empty) ++ (cons 6 (cons (-1) (cons 99 empty) ++ (cons 72 empty)))
> ++ (cons 44 empty ++ (cons 7 (cons 8 (cons 9 (cons 10 (cons 11 empty)))))))
> ++ cons 9 (cons 10 (cons 123 (empty :: SimpleCatDeque BankersDeque Int) ++
> (cons 83 empty))))
>
> <interactive>:28:1-315:
> No instance for (Show1 BankersDeque) arising from a use of 'print'
> In a stmt of an interactive GHCi command: print it
>
> What would the necessary instance look like for BankersDeque?
>
> Thanks,
> Mark
>
> --
> |v\ /\ |\ |< |_ /\ \^| //
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150312/ae027c8b/attachment.html>
More information about the Haskell-Cafe
mailing list