symantic-base-0.3.0.20211007: Basic symantics combinators for Embedded Domain-Specific Languages (EDSL)
Safe HaskellNone
LanguageHaskell2010

Symantic.ADT

Description

EOT (Either of Tuples) to/from ADT (Algebraic Data Type). to produce or consume custom ADT with (<:>) and (<+>).

This is like what is done in generic-sop: https://hackage.haskell.org/package/generics-sop-0.5.1.0/docs/src/Generics.SOP.GGP.html#gSumFrom but using directly Either and Tuples instead of passing by the intermediary GADTs NP and NS.

Synopsis

Type family EoT

type family EoT (adt :: [[*]]) :: * where ... Source #

Equations

EoT '[] = Void 
EoT '[ps] = Tuples ps 
EoT (ps ': ss) = Either (Tuples ps) (EoT ss) 

Type family Tuples

type family Tuples (as :: [*]) :: r :: * where ... Source #

Return the type of snd-nested 2-tuples from the given list of types.

Equations

Tuples '[] = () 
Tuples '[a] = a 
Tuples (a ': rest) = (a, Tuples rest) 

Type ADT

type ADT (adt :: *) = ListOfRepSums (Rep adt) '[] Source #

Normalized type-level representation of an Algebraic Data Type.

Type family ListOfRepSums

type family ListOfRepSums (a :: * -> *) (ss :: [[*]]) :: [[*]] Source #

Collect the alternatives in a continuation passing-style.

Instances

Instances details
type ListOfRepSums (V1 :: Type -> Type) ss Source #

Empty datatypes

Instance details

Defined in Symantic.ADT

type ListOfRepSums (V1 :: Type -> Type) ss = ss
type ListOfRepSums (a :+: b) ss Source # 
Instance details

Defined in Symantic.ADT

type ListOfRepSums (a :+: b) ss = ListOfRepSums a (ListOfRepSums b ss)
type ListOfRepSums (M1 D _c a) ss Source #

Meta-information for datatypes

Instance details

Defined in Symantic.ADT

type ListOfRepSums (M1 D _c a) ss = ListOfRepSums a ss
type ListOfRepSums (M1 C _c a) ss Source #

Meta-information for constructors

Instance details

Defined in Symantic.ADT

type ListOfRepSums (M1 C _c a) ss = ListOfRepProducts a ('[] :: [Type]) ': ss

Type family ListOfRepProducts

type family ListOfRepProducts (a :: * -> *) (ps :: [*]) :: [*] Source #

Collect the records in a continuation passing-style.

Instances

Instances details
type ListOfRepProducts (U1 :: Type -> Type) ps Source #

Constructor without fields

Instance details

Defined in Symantic.ADT

type ListOfRepProducts (U1 :: Type -> Type) ps = ps
type ListOfRepProducts (a :*: b) ps Source # 
Instance details

Defined in Symantic.ADT

type ListOfRepProducts (M1 S _c a) ps Source #

Meta-information for record selectors

Instance details

Defined in Symantic.ADT

type ListOfRepProducts (M1 S _c a) ps = TypeOfRepField a ': ps

Type family TypeOfRepField

type family TypeOfRepField (a :: * -> *) :: * Source #

Instances

Instances details
type TypeOfRepField (K1 _i a :: Type -> Type) Source # 
Instance details

Defined in Symantic.ADT

type TypeOfRepField (K1 _i a :: Type -> Type) = a

Class RepOfEoT

type RepOfEoT a = RepOfEithers (Rep a) '[] Source #

adtOfeot :: Generic a => RepOfEoT a => EoT (ADT a) -> a Source #

Morph the Either of Tuples corresponding to an ADT into a constructor of this ADT. This is the reverse of eotOfadt.

Class RepOfEithers

class RepOfEithers (a :: * -> *) ss where Source #

Methods

repOfEithers :: EoT (ListOfRepSums a ss) -> (a x -> r) -> (EoT ss -> r) -> r Source #

Parse the Either (list-like) binary tree of EoT into the (:+:) (balanced) binary tree of Rep, using continuation passing-style for performance.

Instances

Instances details
RepOfEithers (V1 :: Type -> Type) ss Source # 
Instance details

Defined in Symantic.ADT

Methods

repOfEithers :: EoT (ListOfRepSums V1 ss) -> (V1 x -> r) -> (EoT ss -> r) -> r Source #

(RepOfEithers a (ListOfRepSums b ss), RepOfEithers b ss) => RepOfEithers (a :+: b) ss Source # 
Instance details

Defined in Symantic.ADT

Methods

repOfEithers :: EoT (ListOfRepSums (a :+: b) ss) -> ((a :+: b) x -> r) -> (EoT ss -> r) -> r Source #

RepOfEithers a ss => RepOfEithers (M1 D c a) ss Source # 
Instance details

Defined in Symantic.ADT

Methods

repOfEithers :: EoT (ListOfRepSums (M1 D c a) ss) -> (M1 D c a x -> r) -> (EoT ss -> r) -> r Source #

RepOfTuples a ('[] :: [Type]) => RepOfEithers (M1 C c a) ('[] :: [[Type]]) Source # 
Instance details

Defined in Symantic.ADT

Methods

repOfEithers :: EoT (ListOfRepSums (M1 C c a) '[]) -> (M1 C c a x -> r) -> (EoT '[] -> r) -> r Source #

RepOfTuples a ('[] :: [Type]) => RepOfEithers (M1 C c a) (ps ': ss) Source # 
Instance details

Defined in Symantic.ADT

Methods

repOfEithers :: EoT (ListOfRepSums (M1 C c a) (ps ': ss)) -> (M1 C c a x -> r) -> (EoT (ps ': ss) -> r) -> r Source #

Class RepOfTuples

class RepOfTuples (a :: * -> *) (xs :: [*]) where Source #

Methods

repOfTuples :: Tuples (ListOfRepProducts a xs) -> (a x -> Tuples xs -> r) -> r Source #

Parse the Tuples (list-like) binary tree of EoT into the (:*:) (balanced) binary tree of Rep, using continuation passing-style for performance.

Instances

Instances details
RepOfTuples (U1 :: Type -> Type) ps Source # 
Instance details

Defined in Symantic.ADT

Methods

repOfTuples :: Tuples (ListOfRepProducts U1 ps) -> (U1 x -> Tuples ps -> r) -> r Source #

(RepOfTuples a (ListOfRepProducts b ps), RepOfTuples b ps) => RepOfTuples (a :*: b) ps Source # 
Instance details

Defined in Symantic.ADT

Methods

repOfTuples :: Tuples (ListOfRepProducts (a :*: b) ps) -> ((a :*: b) x -> Tuples ps -> r) -> r Source #

RepOfField a => RepOfTuples (M1 S c a) ('[] :: [Type]) Source # 
Instance details

Defined in Symantic.ADT

Methods

repOfTuples :: Tuples (ListOfRepProducts (M1 S c a) '[]) -> (M1 S c a x -> Tuples '[] -> r) -> r Source #

RepOfField a => RepOfTuples (M1 S c a) (p ': ps) Source # 
Instance details

Defined in Symantic.ADT

Methods

repOfTuples :: Tuples (ListOfRepProducts (M1 S c a) (p ': ps)) -> (M1 S c a x -> Tuples (p ': ps) -> r) -> r Source #

Class RepOfField

class RepOfField (a :: * -> *) where Source #

Methods

repOfField :: TypeOfRepField a -> a x Source #

Instances

Instances details
RepOfField (K1 i a :: Type -> Type) Source # 
Instance details

Defined in Symantic.ADT

Methods

repOfField :: TypeOfRepField (K1 i a) -> K1 i a x Source #

Class EoTOfRep

type EoTOfRep a = EithersOfRep (Rep a) '[] Source #

eotOfadt :: Generic a => EoTOfRep a => a -> EoT (ADT a) Source #

Morph the constructor of an ADT into the corresponding Either of Tuples of this ADT. This is the reverse of adtOfeot.

Class EithersOfRep

class EithersOfRep (a :: * -> *) ss where Source #

Instances

Instances details
EithersOfRep (V1 :: Type -> Type) ss Source # 
Instance details

Defined in Symantic.ADT

(EithersOfRep a (ListOfRepSums b ss), EithersOfRep b ss) => EithersOfRep (a :+: b) ss Source # 
Instance details

Defined in Symantic.ADT

Methods

eithersOfRepL :: (a :+: b) x -> EoT (ListOfRepSums (a :+: b) ss) Source #

eithersOfRepR :: EoT ss -> EoT (ListOfRepSums (a :+: b) ss) Source #

EithersOfRep a ss => EithersOfRep (M1 D c a) ss Source # 
Instance details

Defined in Symantic.ADT

Methods

eithersOfRepL :: M1 D c a x -> EoT (ListOfRepSums (M1 D c a) ss) Source #

eithersOfRepR :: EoT ss -> EoT (ListOfRepSums (M1 D c a) ss) Source #

TuplesOfRep a ('[] :: [Type]) => EithersOfRep (M1 C c a) ('[] :: [[Type]]) Source # 
Instance details

Defined in Symantic.ADT

Methods

eithersOfRepL :: M1 C c a x -> EoT (ListOfRepSums (M1 C c a) '[]) Source #

eithersOfRepR :: EoT '[] -> EoT (ListOfRepSums (M1 C c a) '[]) Source #

TuplesOfRep a ('[] :: [Type]) => EithersOfRep (M1 C c a) (ps ': ss) Source # 
Instance details

Defined in Symantic.ADT

Methods

eithersOfRepL :: M1 C c a x -> EoT (ListOfRepSums (M1 C c a) (ps ': ss)) Source #

eithersOfRepR :: EoT (ps ': ss) -> EoT (ListOfRepSums (M1 C c a) (ps ': ss)) Source #

Class TuplesOfRep

class TuplesOfRep (a :: * -> *) (ps :: [*]) where Source #

Methods

tuplesOfRep :: a x -> Tuples ps -> Tuples (ListOfRepProducts a ps) Source #

Instances

Instances details
TuplesOfRep (U1 :: Type -> Type) ps Source # 
Instance details

Defined in Symantic.ADT

(TuplesOfRep a (ListOfRepProducts b ps), TuplesOfRep b ps) => TuplesOfRep (a :*: b) ps Source # 
Instance details

Defined in Symantic.ADT

Methods

tuplesOfRep :: (a :*: b) x -> Tuples ps -> Tuples (ListOfRepProducts (a :*: b) ps) Source #

FieldOfRep a => TuplesOfRep (M1 S c a) ('[] :: [Type]) Source # 
Instance details

Defined in Symantic.ADT

Methods

tuplesOfRep :: M1 S c a x -> Tuples '[] -> Tuples (ListOfRepProducts (M1 S c a) '[]) Source #

FieldOfRep a => TuplesOfRep (M1 S c a) (x ': ps) Source # 
Instance details

Defined in Symantic.ADT

Methods

tuplesOfRep :: M1 S c a x0 -> Tuples (x ': ps) -> Tuples (ListOfRepProducts (M1 S c a) (x ': ps)) Source #

Class FieldOfRep

class FieldOfRep (a :: * -> *) where Source #

Methods

fieldOfRep :: a x -> TypeOfRepField a Source #

Instances

Instances details
FieldOfRep (K1 i a :: Type -> Type) Source # 
Instance details

Defined in Symantic.ADT

Methods

fieldOfRep :: K1 i a x -> TypeOfRepField (K1 i a) Source #