extensible-0.5.1: 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 :: (Lookup xs k v, 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, Lookup xs k v, 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) :: forall k. [k] -> k -> Type #

A witness that of x is a member of a type level set xs.

Instances
Eq (Membership xs x) 
Instance details

Defined in Type.Membership.Internal

Methods

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

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

Ord (Membership xs x) 
Instance details

Defined in Type.Membership.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) 
Instance details

Defined in Type.Membership.Internal

Methods

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

show :: Membership xs x -> String #

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

Semigroup (Membership xs x) 
Instance details

Defined in Type.Membership.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) 
Instance details

Defined in Type.Membership.Internal

Methods

lift :: Membership xs x -> Q Exp #

Hashable (Membership xs x) 
Instance details

Defined in Type.Membership.Internal

Methods

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

hash :: Membership xs x -> Int #

NFData (Membership xs x) 
Instance details

Defined in Type.Membership.Internal

Methods

rnf :: Membership xs x -> () #

Pretty (Membership xs x) 
Instance details

Defined in Type.Membership.Internal

Methods

pretty :: Membership xs x -> Doc ann #

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

mkMembership :: Int -> Q Exp #

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

getMemberId :: Membership xs x -> Int #

get the position as an Int.

compareMembership :: Membership xs x -> Membership xs y -> Either Ordering (x :~: y) #

Compare two Memberships.

leadership :: Membership (x ': xs) x #

This Membership points to the first element

Member

class Member (xs :: [k]) (x :: k) where #

x is a member of xs

Methods

membership :: Membership xs x #

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

Defined in Type.Membership.Internal

Methods

membership :: Membership xs x #

type (∈) (x :: k) (xs :: [k]) = Member xs x #

Unicode flipped alias for Member

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

FindType types

Equations

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

Generation

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

Every type-level list is an instance of Generate.

Methods

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

Enumerate all possible Memberships of xs.

hcount :: proxy xs -> Int #

Count the number of memberships.

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

Enumerate Memberships and construct an HList.

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

Defined in Type.Membership

Methods

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

hcount :: proxy [] -> Int #

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

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

Defined in Type.Membership

Methods

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

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

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

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

Every element in xs satisfies c

Methods

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

Enumerate all possible Memberships of xs with an additional context.

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

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

Defined in Type.Membership

Methods

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

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

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

Defined in Type.Membership

Methods

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

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

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

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

Equations

ForallF (c :: k -> Constraint) ([] :: [k]) = () 
ForallF (c :: k -> Constraint) (x ': xs :: [k]) = (c x, Forall c xs) 

Association

data Assoc k v #

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 (KeyTargetAre 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 (KeyTargetAre 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 (KeyTargetAre KnownSymbol (Instance1 FromJSON h)) xs => FromJSON (Nullable (Field h :: Assoc Symbol v -> Type) :* xs) Source # 
Instance details

Defined in Data.Extensible.Dictionary

Forall (KeyTargetAre 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 (KeyTargetAre KnownSymbol (Instance1 FromField h)) xs => FromNamedRecord ((Field h :: Assoc Symbol v -> Type) :* xs) Source # 
Instance details

Defined in Data.Extensible.Dictionary

Forall (KeyTargetAre 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 (TargetOf kv)

type (>:) = ((:>) :: k -> v -> Assoc k v) #

A synonym for (:>)

class Lookup (xs :: [Assoc k v]) (k1 :: k) (v1 :: v) | k1 xs -> v1 where #

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

Methods

association :: Membership xs (k1 :> v1) #

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

Defined in Type.Membership.Internal

Methods

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

type Associate k v xs = Lookup xs k v Source #

Deprecated: Use Lookup instead

Misc

type family Head (xs :: [k]) :: k where ... Source #

First element

Equations

Head (x ': xs) = x 

type family Last (x :: [k]) :: k where ... Source #

Last element

Equations

Last '[x] = x 
Last (x ': xs) = Last xs