extensible-0.3.5: Extensible, efficient, lens-friendly data types

Copyright(c) Fumiaki Kinoshita 2015
LicenseBSD3
MaintainerFumiaki Kinoshita <fumiexcel@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellTrustworthy
LanguageHaskell2010

Data.Extensible.Internal

Contents

Description

A bunch of combinators that contains magic

Synopsis

Membership

data Membership xs x Source

The position of x in the type level set xs.

Instances

Typeable ([k] -> k -> *) (Membership k) 
Eq (Membership k xs x) 
Ord (Membership k xs x) 
Show (Membership k xs x) 

mkMembership :: Int -> Q Exp Source

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

runMembership :: 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

class Member xs x where Source

Instances

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

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 xs :: [Nat] Source

FindType types

Equations

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

Association

data Assoc k v Source

The kind of key-value pairs

Constructors

k :> v infix 0 

Instances

Associate k k1 k2 v xs => Associated (Assoc k k) xs ((:>) k k k v) 
Wrapper k h => Wrapper (Assoc k k) (Field k k h) 
type Repr (Assoc k1 k) (Field k k1 h) kv = Repr k h (AssocValue k k1 kv) 

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

((~) (Elaborated k (Assoc Nat k1)) (Elaborate k (Assoc Nat k1) k2 (FindAssoc k1 k k1 k2 xs)) (Expecting k (Assoc Nat k1) ((:>) Nat k1 n v)), KnownPosition Nat n) => Associate k k k v xs 

type family FindAssoc key xs Source

Equations

FindAssoc k ((k :> v) : xs) = (Zero :> v) : MapSuccKey (FindAssoc k xs) 
FindAssoc k ((k' :> v) : xs) = MapSuccKey (FindAssoc k xs) 
FindAssoc k [] = [] 

Sugar

type family Elaborate key xs :: Elaborated k v Source

Equations

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

data Elaborated k v Source

Constructors

Expecting v 
Missing k 
Duplicate k 

Tree navigation

data NavHere xs x where Source

Ensure that the first element of xs is x

Constructors

Here :: NavHere (x : xs) x 

navigate :: (NavHere xs x -> r) -> (Membership (Half (Tail xs)) x -> r) -> (Membership (Half (Tail (Tail xs))) x -> r) -> Membership xs x -> r Source

PRIVILEGED: Navigate a tree.

here :: Membership (x : xs) x Source

The Membership points the first element

navNext :: Membership xs y -> Membership (x : xs) y Source

The next membership

navL :: Membership (Half xs) y -> Membership (x : xs) y Source

Describes the relation of Membership within a tree

navR :: Membership (Half (Tail xs)) y -> Membership (x : xs) y Source

Describes the relation of Membership within a tree

Miscellaneous

data Nat Source

Type level binary number

Constructors

Zero 
DNat Nat 
SDNat Nat 

class KnownPosition n where Source

Converts type naturals into Word.

Methods

theInt :: proxy n -> Word Source

type family Succ x :: Nat Source

The successor of the number

Equations

Succ Zero = SDNat Zero 
Succ (DNat n) = SDNat n 
Succ (SDNat n) = DNat (Succ n) 

type family Half xs :: [k] Source

Interleaved list

Equations

Half [] = [] 
Half (x : (y : zs)) = x : Half zs 
Half (x : []) = `[x]` 

type family Head xs :: k Source

Equations

Head (x : xs) = x 

type family Tail xs :: [k] Source

Type-level tail

Equations

Tail (x : xs) = xs 
Tail [] = [] 

type family xs ++ ys :: [k] infixr 5 Source

Type level ++

Equations

[] ++ ys = ys 
(x : xs) ++ ys = x : (xs ++ ys) 

type family Map f xs :: [k] Source

Type level map

Equations

Map f [] = [] 
Map f (x : xs) = f x : Map f xs 

type family Merge xs ys :: [k] Source

Type level merging

Equations

Merge (x : xs) (y : ys) = x : (y : Merge xs ys) 
Merge xs [] = xs 
Merge [] ys = ys 

type family Concat xs :: [k] Source

Type level concat

Equations

Concat [] = [] 
Concat (x : xs) = x ++ Concat xs 

module Data.Proxy