-1

I have a function which returns a Subst defined in this library: http://hackage.haskell.org/package/compdata-0.1/docs/Data-Comp-Variables.html#t:Subst

I am trying to print the return value. The printer should show a mapping from variables to terms.

When I try to print the result, I get:

  • No instance for (Show (Cxt NoHole CTypeF ()))
        arising from a use of ‘print’
  • In the expression: (print subst)

I think this means I must implement a printer. I know that when it's a user defined class, I can do 'deriving show'. Could someone point out how I should go about printing this?

Also, this is my CTypeF structure.

data CTypeF a 
    = CVarF Int 
    | CArrF a a
    | CIntF
    | CBoolF
    deriving (Eq, Data, Functor, Foldable, Traversable, Show)

It derives show, so I don't think the issue is here.

Lana
  • 1,124
  • 1
  • 8
  • 17
  • `Cxt` has no `Show` instance and therefore cannot be printed, no matter what parameters you give it. – AJF Jun 17 '19 at 07:15
  • Sorry, but I am new to haskell and I am not understanding your point. I already know the instance is missing and my question is how to implement it. So are you saying you can't define an instance? – Lana Jun 17 '19 at 07:44
  • @Lana It should still be possible to define a `Show` instance for `Ctx`. It would look something like `instance (Show (f (Ctx h f a)), Show a) => Show (Ctx h f a) where show (Term x) = show x show (Hole a) = show a`. Note that this is untested and so may not work the way you want, but a `Show` instance would look something along these lines. – bradrn Jun 17 '19 at 08:26

1 Answers1

1

Cxt has a Show instance, but it requires its f parameter to have an instance of ShowF.

(Functor f, ShowF f, Show a) => Show (Cxt h f a)

So you need to make CTypeF have an instance of ShowF. To do that, you can use makeShowF with Template Haskell.

$(makeShowF ''CTypeF)
4castle
  • 32,613
  • 11
  • 69
  • 106