thorn-0.1.0.2: Template Haskell Library

Safe HaskellNone

Data.Thorn

Contents

Description

Thorn, a template haskell library.

Synopsis

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)

data Variance Source

Variance is a variance of a parameter of a functor.

Constructors

Co

Covariance, one of a normal functor.

Contra

Contravariance, a dual of covariance.

Free

Free-variance, or novariance, being supposed to satisfy either covariance or contravariance.

Fixed

Fixed-variance, or invariance, being suppoesed to satisfy both covariance and contravariance.

Instances

Read Variance 
Show Variance 
Monoid Variance

v1 mappend v2 means to be supposed to satisfy both v1 and v2.

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