module Data.Thorn.FunctorExample (module Data.Thorn.FunctorExample) where
import Data.Thorn
import Data.Char
import Data.Functor.Contravariant
import Data.Bifunctor
import Data.Profunctor
type a :<- b = b -> a
nuf :: Char
nuf = $(autofmap [t|(:<-)|]) chr ord (+1) 'a'
varnuf :: [Variance]
varnuf = $(autovariance [t|(:<-)|])
data Cntr a = Cntr (a -> Int)
autofunctorize [t|Cntr|]
tuple :: (Int,Int,Int)
tuple = $(autofmap $[t|(,,) Int|]) (+1) (+2) (0,0,0)
vartuple :: [Variance]
vartuple = $(autovariance [t|(,,) Int|])
data FunFun a b = FunFun ((b -> a) -> b)
varfunfun :: [Variance]
varfunfun = $(autovariance [t|FunFun|])
autofunctorize [t|FunFun|]
data What a b c = What1 c (a -> c) | What2 a
varwhat :: [Variance]
varwhat = $(autovariance [t|What|])
autofunctorize [t|What T0|]
data List a = Nil | a :* (List a) deriving Show
fromNormalList :: [a] -> List a
fromNormalList [] = Nil
fromNormalList (a : as) = a :* fromNormalList as
toNormalList :: List a -> [a]
toNormalList Nil = []
toNormalList (a :* as) = a : toNormalList as
list :: [Int]
list = toNormalList $ $(autofmap [t|List|]) (+10) (fromNormalList [1..5])
varlist :: [Variance]
varlist = $(autovariance [t|List|])
autofunctorize [t|List|]
data Rose a = Rose a (Forest a) deriving Show
data Forest a = Forest [Rose a] deriving Show
gorose n = Rose n (Forest (replicate n (gorose (n1))))
rose = $(autofmap [t|Rose|]) (+1) (gorose 2)
varrose, varforest :: [Variance]
varrose = $(autovariance [t|Rose|])
varforest = $(autovariance [t|Forest|])
autofunctorize [t|Rose|]
autofunctorize [t|Forest|]