codec-0.1: First-class record construction and bidirectional serialization

Safe HaskellNone
LanguageHaskell2010

Data.Codec.Field

Contents

Synopsis

First-class record construction

data Field r a x y

Describes how to apply a constructor argument and how to extract from a record. y should be x with one argument knocked out: e. g.

Field MyType Int (Int -> a2 -> MyType) (X -> a2 -> MyType)

Constructors

Field (a -> x -> y) (r -> a) 

newtype Build r f x y

An ongoing record construction of an r in context f. Applicative actions are sequenced in the direction of >>>.

Constructors

Build (f (x -> y)) 

Instances

Applicative f => Category * (Build r f) 

data Con r x

A constructor for a given record and a way to check whether it has it.

Constructors

Con x (r -> Bool) 

($>>) :: (Functor f, Buildable r y) => x -> Build r f x y -> f r infixr 1

Infix version of build.

(>>>) :: Category k cat => cat a b -> cat b c -> cat a c infixr 1

Left-to-right composition

done :: Applicative f => Build r f x x

No-op Build (same as id).

data X

Fields partially apply constructors and replace arguments with this type.

Constructors

X 

Instances

Buildable r b => Buildable r (X -> b) 
Field2 (a, b) b (a1 -> b -> (a, b)) (a1 -> X -> (a, b)) 
Field1 (a, b) a (a -> a2 -> (a, b)) (X -> a2 -> (a, b)) 

class Buildable r a where

The class of constructor applications that have been completely filled in by composing Builds. If you see an error message involving this, it means that you forgot to specify a Build for a field.

Methods

give :: a -> r

Instances

Buildable r r 
Buildable r b => Buildable r (X -> b) 

having :: Functor f => Field r a x y -> f a -> Build r f x y

Combine a Field and a way to produce an a to get a Build.

build :: (Functor f, Buildable r y) => x -> Build r f x y -> f r

Finish a construction given a constructor.