{-# LANGUAGE GADTs #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Data.Comp.Show
( ShowF(..)
) where
import Data.Comp.Algebra
import Data.Comp.Annotation
import Data.Comp.Derive (liftSum)
import Data.Comp.Derive.Show
import Data.Comp.Derive.Utils (derive)
import Data.Comp.Term
instance (Functor f, ShowF f) => ShowF (Cxt h f) where
showF :: Cxt h f String -> String
showF (Hole String
s) = String
s
showF (Term f (Cxt h f String)
t) = forall (f :: * -> *). ShowF f => f String -> String
showF forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *). ShowF f => f String -> String
showF f (Cxt h f String)
t
instance (Functor f, ShowF f, Show a) => Show (Cxt h f a) where
show :: Cxt h f a -> String
show = forall (f :: * -> *) h a b.
Functor f =>
Alg f b -> (a -> b) -> Cxt h f a -> b
free forall (f :: * -> *). ShowF f => f String -> String
showF forall a. Show a => a -> String
show
instance (ShowF f, Show p) => ShowF (f :&: p) where
showF :: (:&:) f p String -> String
showF (f String
v :&: p
p) = forall (f :: * -> *). ShowF f => f String -> String
showF f String
v forall a. [a] -> [a] -> [a]
++ String
" :&: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show p
p
$(derive [liftSum] [''ShowF])
$(derive [makeShowF] [''Maybe, ''[], ''(,)])
instance (ShowConstr f, Show p) => ShowConstr (f :&: p) where
showConstr :: forall a. (:&:) f p a -> String
showConstr (f a
v :&: p
p) = forall (f :: * -> *) a. ShowConstr f => f a -> String
showConstr f a
v forall a. [a] -> [a] -> [a]
++ String
" :&: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show p
p
$(derive [liftSum] [''ShowConstr])