Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell: deriving Show for Fix types

I'm trying to implement a recursive datatype using recursion-schemes. I would like to be able to print it.

import Data.Functor.Foldable

data T1F a = Foo deriving Show
type T1 = Fix T1F
data T2 = Bar T1 deriving Show -- error here

Error message:

No instance for (Data.Functor.Classes.Show1 T1F)
  arising from the first field of ‘Bar’ (type ‘T1’)
Possible fix:
  use a standalone 'deriving instance' declaration,
    so you can specify the instance context yourself
When deriving the instance for (Show T2)

How do I make T1 derive Show?

like image 426
Carl Patenaude Poulin Avatar asked Mar 21 '17 18:03

Carl Patenaude Poulin


1 Answers

Using the package deriving-compat:

{-# LANGUAGE TemplateHaskell #-}
import Data.Functor.Foldable
import Text.Show.Deriving

data T1F a = Foo deriving Show
$(deriveShow1 ''T1F)
type T1 = Fix T1F
data T2 = Bar T1 deriving Show
like image 178
Carl Patenaude Poulin Avatar answered Nov 13 '22 11:11

Carl Patenaude Poulin