| Safe Haskell | None |
|---|
Data.Thorn
Contents
Description
Thorn, a template haskell library.
Data.Thorn.Fmap
autofmap :: TypeQ -> ExpQSource
autofmap t generates the fmap of the type t.
Quite surprisingly, it still works for any arities, co/contra/free/fixed-variances, partially applied types, type synonyms, and mutual recursions.
type Nuf x y = y -> x
type a :<- b = Nuf a b
nuf = $(autofmap [t|(:<-)|]) chr ord (+1) c
data List a = Nil | Cons a (List a) deriving Show
golist 0 = Nil
golist n = Cons n (golist (n-1))
list = $(autofmap $[t|List|]) (+1) (golist 10)
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 (n-1))))
rose = $(autofmap $[t|Rose|]) (+1) (gorose 3)
Variance is a variance of a parameter of a functor.
autovariance :: TypeQ -> ExpQSource
autovariance t provides the variances of the type t.
autofunctorize :: TypeQ -> DecsQSource
autofunctorize t provides an instance delcaration of the type t for the suitable functor class : Funtor, Contravariant, Bifunctor, or Profunctor