extensible-0.5: Extensible, efficient, optics-friendly data types and effects

Copyright(c) Fumiaki Kinoshita 2018
LicenseBSD3
MaintainerFumiaki Kinoshita <fumiexcel@gmail.com>
Safe HaskellNone
LanguageHaskell2010

Data.Extensible.Class

Contents

Description

 
Synopsis

Class

class (Functor f, Profunctor p) => Extensible f p (t :: (k -> *) -> [k] -> *) where Source #

This class allows us to use pieceAt for both sums and products.

Associated Types

type ExtensibleConstr t (h :: k -> *) (xs :: [k]) (x :: k) :: Constraint Source #

Methods

pieceAt :: ExtensibleConstr t h xs x => Membership xs x -> Optic' p f (t h xs) (h x) Source #

Instances
(Applicative f, Choice p) => Extensible f p ((:|) :: (k -> Type) -> [k] -> Type) Source # 
Instance details

Defined in Data.Extensible.Sum

Associated Types

type ExtensibleConstr (:|) h xs x :: Constraint Source #

Methods

pieceAt :: ExtensibleConstr (:|) h xs x => Membership xs x -> Optic' p f (h :| xs) (h x) Source #

(Corepresentable p, Comonad (Corep p), Functor f) => Extensible f p ((:*) :: (k -> Type) -> [k] -> Type) Source # 
Instance details

Defined in Data.Extensible.Struct

Associated Types

type ExtensibleConstr (:*) h xs x :: Constraint Source #

Methods

pieceAt :: ExtensibleConstr (:*) h xs x => Membership xs x -> Optic' p f (h :* xs) (h x) Source #

(Functor f, Profunctor p) => Extensible f p (Inextensible :: (k -> Type) -> [k] -> Type) Source # 
Instance details

Defined in Data.Extensible.Field

Associated Types

type ExtensibleConstr Inextensible h xs x :: Constraint Source #

Methods

pieceAt :: ExtensibleConstr Inextensible h xs x => Membership xs x -> Optic' p f (Inextensible h xs) (h x) Source #

(Corepresentable p, Comonad (Corep p), Functor f) => Extensible f p (BitProd r :: (k -> Type) -> [k] -> Type) Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type ExtensibleConstr (BitProd r) h xs x :: Constraint Source #

Methods

pieceAt :: ExtensibleConstr (BitProd r) h xs x => Membership xs x -> Optic' p f (BitProd r h xs) (h x) Source #

piece :: (x xs, Extensible f p t, ExtensibleConstr t h xs x) => Optic' p f (t h xs) (h x) Source #

Accessor for an element.

pieceAssoc :: (Associate k v xs, Extensible f p t, ExtensibleConstr t h xs (k :> v)) => Optic' p f (t h xs) (h (k :> v)) Source #

Like piece, but reckon membership from its key.

itemAt :: (Wrapper h, Extensible f p t, ExtensibleConstr t h xs x) => Membership xs x -> Optic' p f (t h xs) (Repr h x) Source #

Access a specified element through a wrapper.

item :: (Wrapper h, Extensible f p t, x xs, ExtensibleConstr t h xs x) => proxy x -> Optic' p f (t h xs) (Repr h x) Source #

Access an element through a wrapper.

itemAssoc :: (Wrapper h, Extensible f p t, Associate k v xs, ExtensibleConstr t h xs (k :> v)) => proxy k -> Optic' p f (t h xs) (Repr h (k :> v)) Source #

Access an element specified by the key type through a wrapper.

Membership

data Membership (xs :: [k]) (x :: k) Source #

The position of x in the type level set xs.

Instances
Eq (Membership xs x) Source # 
Instance details

Defined in Data.Extensible.Internal

Methods

(==) :: Membership xs x -> Membership xs x -> Bool #

(/=) :: Membership xs x -> Membership xs x -> Bool #

Ord (Membership xs x) Source # 
Instance details

Defined in Data.Extensible.Internal

Methods

compare :: Membership xs x -> Membership xs x -> Ordering #

(<) :: Membership xs x -> Membership xs x -> Bool #

(<=) :: Membership xs x -> Membership xs x -> Bool #

(>) :: Membership xs x -> Membership xs x -> Bool #

(>=) :: Membership xs x -> Membership xs x -> Bool #

max :: Membership xs x -> Membership xs x -> Membership xs x #

min :: Membership xs x -> Membership xs x -> Membership xs x #

Show (Membership xs x) Source # 
Instance details

Defined in Data.Extensible.Internal

Methods

showsPrec :: Int -> Membership xs x -> ShowS #

show :: Membership xs x -> String #

showList :: [Membership xs x] -> ShowS #

Semigroup (Membership xs x) Source # 
Instance details

Defined in Data.Extensible.Internal

Methods

(<>) :: Membership xs x -> Membership xs x -> Membership xs x #

sconcat :: NonEmpty (Membership xs x) -> Membership xs x #

stimes :: Integral b => b -> Membership xs x -> Membership xs x #

Lift (Membership xs x) Source # 
Instance details

Defined in Data.Extensible.Internal

Methods

lift :: Membership xs x -> Q Exp #

Hashable (Membership xs x) Source # 
Instance details

Defined in Data.Extensible.Internal

Methods

hashWithSalt :: Int -> Membership xs x -> Int #

hash :: Membership xs x -> Int #

NFData (Membership xs x) Source # 
Instance details

Defined in Data.Extensible.Internal

Methods

rnf :: Membership xs x -> () #

Pretty (Membership xs x) Source # 
Instance details

Defined in Data.Extensible.Internal

Methods

pretty :: Membership xs x -> Doc ann #

prettyList :: [Membership xs x] -> Doc ann #

mkMembership :: Int -> Q Exp Source #

Generates a Membership that corresponds to the given ordinal (0-origin).

getMemberId :: Membership xs x -> Int Source #

get the position as an Int.

leadership :: Membership (y ': xs) x -> ((x :~: y) -> r) -> (Membership xs x -> r) -> r Source #

Embodies a type equivalence to ensure that the Membership points the first element.

Member

class Member xs x where Source #

x is a member of xs

Methods

membership :: Membership xs x Source #

Instances
(Elaborate x (FindType x xs) ~ (Expecting pos :: Elaborated k Nat), KnownNat pos) => Member (xs :: [k]) (x :: k) Source # 
Instance details

Defined in Data.Extensible.Internal

Methods

membership :: Membership xs x Source #

remember :: forall xs x r. Membership xs x -> (Member xs x => r) -> r Source #

Remember that Member xs x from Membership.

type (∈) x xs = Member xs x Source #

Unicode flipped alias for Member

type family FindType (x :: k) (xs :: [k]) :: [Nat] where ... Source #

FindType types

Equations

FindType x (x ': xs) = 0 ': FindType x xs 
FindType x (y ': ys) = MapSucc (FindType x ys) 
FindType x '[] = '[] 

Generation

class Generate (xs :: [k]) where Source #

Every type-level list is an instance of Generate.

Methods

henumerate :: (forall x. Membership xs x -> r -> r) -> r -> r Source #

Enumerate all possible Memberships of xs.

hcount :: proxy xs -> Int Source #

Count the number of memberships.

hgenerateList :: Applicative f => (forall x. Membership xs x -> f (h x)) -> f (HList h xs) Source #

Enumerate Memberships and construct an HList.

Instances
Generate ([] :: [k]) Source # 
Instance details

Defined in Data.Extensible.Class

Methods

henumerate :: (forall (x :: k0). Membership [] x -> r -> r) -> r -> r Source #

hcount :: proxy [] -> Int Source #

hgenerateList :: Applicative f => (forall (x :: k0). Membership [] x -> f (h x)) -> f (HList h []) Source #

Generate xs => Generate (x ': xs :: [k]) Source # 
Instance details

Defined in Data.Extensible.Class

Methods

henumerate :: (forall (x0 :: k0). Membership (x ': xs) x0 -> r -> r) -> r -> r Source #

hcount :: proxy (x ': xs) -> Int Source #

hgenerateList :: Applicative f => (forall (x0 :: k0). Membership (x ': xs) x0 -> f (h x0)) -> f (HList h (x ': xs)) Source #

class (ForallF c xs, Generate xs) => Forall (c :: k -> Constraint) (xs :: [k]) where Source #

Every element in xs satisfies c

Methods

henumerateFor :: proxy c -> proxy' xs -> (forall x. c x => Membership xs x -> r -> r) -> r -> r Source #

Enumerate all possible Memberships of xs with an additional context.

hgenerateListFor :: Applicative f => proxy c -> (forall x. c x => Membership xs x -> f (h x)) -> f (HList h xs) Source #

Instances
Forall (c :: k -> Constraint) ([] :: [k]) Source # 
Instance details

Defined in Data.Extensible.Class

Methods

henumerateFor :: proxy c -> proxy' [] -> (forall (x :: k0). c x => Membership [] x -> r -> r) -> r -> r Source #

hgenerateListFor :: Applicative f => proxy c -> (forall (x :: k0). c x => Membership [] x -> f (h x)) -> f (HList h []) Source #

(c x, Forall c xs) => Forall (c :: a -> Constraint) (x ': xs :: [a]) Source # 
Instance details

Defined in Data.Extensible.Class

Methods

henumerateFor :: proxy c -> proxy' (x ': xs) -> (forall (x0 :: k). c x0 => Membership (x ': xs) x0 -> r -> r) -> r -> r Source #

hgenerateListFor :: Applicative f => proxy c -> (forall (x0 :: k). c x0 => Membership (x ': xs) x0 -> f (h x0)) -> f (HList h (x ': xs)) Source #

type family ForallF (c :: k -> Constraint) (xs :: [k]) :: Constraint where ... Source #

HACK: Without this, the constraints are not propagated well.

Equations

ForallF c '[] = () 
ForallF c (x ': xs) = (c x, Forall c xs) 

Association

data Assoc k v Source #

The kind of key-value pairs

Constructors

k :> v infix 0 
Instances
Wrapper h => Wrapper (Field h :: Assoc k v -> Type) Source # 
Instance details

Defined in Data.Extensible.Field

Associated Types

type Repr (Field h) v :: Type Source #

Methods

_Wrapper :: (Functor f, Profunctor p) => Optic' p f (Field h v0) (Repr (Field h) v0) Source #

wrap :: Repr (Field h) v0 -> Field h v0 Source #

unwrap :: Field h v0 -> Repr (Field h) v0 Source #

Forall (KeyValue KnownSymbol (Instance1 ToJSON h)) xs => ToJSON (Nullable (Field h :: Assoc Symbol v -> Type) :* xs) Source # 
Instance details

Defined in Data.Extensible.Dictionary

Methods

toJSON :: (Nullable (Field h) :* xs) -> Value #

toEncoding :: (Nullable (Field h) :* xs) -> Encoding #

toJSONList :: [Nullable (Field h) :* xs] -> Value #

toEncodingList :: [Nullable (Field h) :* xs] -> Encoding #

Forall (KeyValue KnownSymbol (Instance1 ToJSON h)) xs => ToJSON ((Field h :: Assoc Symbol v -> Type) :* xs) Source # 
Instance details

Defined in Data.Extensible.Dictionary

Methods

toJSON :: (Field h :* xs) -> Value #

toEncoding :: (Field h :* xs) -> Encoding #

toJSONList :: [Field h :* xs] -> Value #

toEncodingList :: [Field h :* xs] -> Encoding #

Forall (KeyValue KnownSymbol (Instance1 FromJSON h)) xs => FromJSON (Nullable (Field h :: Assoc Symbol v -> Type) :* xs) Source # 
Instance details

Defined in Data.Extensible.Dictionary

Forall (KeyValue KnownSymbol (Instance1 FromJSON h)) xs => FromJSON ((Field h :: Assoc Symbol v -> Type) :* xs) Source #

parseJSON Null is called for missing fields.

Instance details

Defined in Data.Extensible.Dictionary

Methods

parseJSON :: Value -> Parser (Field h :* xs) #

parseJSONList :: Value -> Parser [Field h :* xs] #

Forall (KeyValue KnownSymbol (Instance1 FromField h)) xs => FromNamedRecord ((Field h :: Assoc Symbol v -> Type) :* xs) Source # 
Instance details

Defined in Data.Extensible.Dictionary

Forall (KeyValue KnownSymbol (Instance1 ToField h)) xs => ToNamedRecord ((Field h :: Assoc Symbol v -> Type) :* xs) Source # 
Instance details

Defined in Data.Extensible.Dictionary

Methods

toNamedRecord :: (Field h :* xs) -> NamedRecord #

type Repr (Field h :: Assoc k v -> Type) (kv :: Assoc k v) Source # 
Instance details

Defined in Data.Extensible.Field

type Repr (Field h :: Assoc k v -> Type) (kv :: Assoc k v) = Repr h (AssocValue kv)

type (>:) = (:>) Source #

A synonym for (:>)

class Associate k v xs | k xs -> v where Source #

Associate k v xs is essentially identical to (k :> v) ∈ xs , but the type v is inferred from k and xs.

Methods

association :: Membership xs (k :> v) Source #

Instances
(Elaborate k2 (FindAssoc 0 k2 xs) ~ (Expecting (n :> v2) :: Elaborated k1 (Assoc Nat v1)), KnownNat n) => Associate (k2 :: k1) (v2 :: v1) (xs :: [Assoc k1 v1]) Source # 
Instance details

Defined in Data.Extensible.Internal

Methods

association :: Membership xs (k2 :> v2) Source #

type family FindAssoc (n :: Nat) (key :: k) (xs :: [Assoc k v]) where ... Source #

Find a type associated to the specified key.

Equations

FindAssoc n k ((k :> v) ': xs) = (n :> v) ': FindAssoc (1 + n) k xs 
FindAssoc n k ((k' :> v) ': xs) = FindAssoc (1 + n) k xs 
FindAssoc n k '[] = '[] 

Sugar

type family Elaborate (key :: k) (xs :: [v]) :: Elaborated k v where ... Source #

Make the result more readable

Equations

Elaborate k '[] = Missing k 
Elaborate k '[x] = Expecting x 
Elaborate k xs = Duplicate k 

data Elaborated k v Source #

A readable type search result

Constructors

Expecting v 
Missing k 
Duplicate k