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

Copyright(c) Fumiaki Kinoshita 2017
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.

Minimal complete definition

pieceAt

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 k f p ((:|) k) Source # 

Associated Types

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

Methods

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

(Corepresentable p, Comonad (Corep p), Functor f) => Extensible k f p ((:*) k) Source # 

Associated Types

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

Methods

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

(Functor f, Profunctor p) => Extensible k f p (Inextensible k) Source # 

Associated Types

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

Methods

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

(Corepresentable p, Comonad (Corep p), Functor f) => Extensible k f p (BitProd k r) Source # 

Associated Types

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

Methods

pieceAt :: ExtensibleConstr f t h xs x => Membership f xs x -> Optic' * * (BitProd k r) p (t 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 k xs x) Source # 

Methods

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

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

Ord (Membership k xs x) Source # 

Methods

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

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

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

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

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

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

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

Show (Membership k xs x) Source # 

Methods

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

show :: Membership k xs x -> String #

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

Semigroup (Membership k xs x) Source # 

Methods

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

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

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

Hashable (Membership k xs x) Source # 

Methods

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

hash :: Membership k xs x -> Int #

NFData (Membership k xs x) Source # 

Methods

rnf :: Membership k xs x -> () #

mkMembership :: Int -> Q Exp Source #

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

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

Minimal complete definition

membership

Methods

membership :: Membership xs x Source #

Instances

((~) (Elaborated k Nat) (Elaborate k Nat x (FindType k x xs)) (Expecting k Nat pos), KnownNat pos) => Member k xs x Source # 

Methods

membership :: Membership xs x 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.

Minimal complete definition

henumerate, hcount, hgenerateList

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 ([] k) Source # 

Methods

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

hcount :: proxy xs -> Int Source #

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

Generate k xs => Generate k ((:) k x xs) Source # 

Methods

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

hcount :: proxy xs -> Int Source #

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

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

Every element in xs satisfies c

Minimal complete definition

henumerateFor, hgenerateListFor

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 k c ([] k) Source # 

Methods

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

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

(c x, Forall a c xs) => Forall a c ((:) a x xs) Source # 

Methods

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

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

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

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 v h => Wrapper (Assoc k v) (Field k v h) Source # 

Associated Types

type Repr (Field k v h) (h :: Field k v h -> *) (v :: Field k v h) :: * Source #

Methods

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

type Repr (Assoc k v) (Field k v h) kv Source # 
type Repr (Assoc k v) (Field k v h) kv = Repr v h (AssocValue k v 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.

Minimal complete definition

association

Methods

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

Instances

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

Methods

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

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

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 #

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