apiary-2.1.2: Simple and type safe web framework that generate web API documentation.

Safe HaskellNone
LanguageHaskell2010

Data.Apiary.Routing.Dict

Contents

Synopsis

store

data Store kvs Source #

Instances

ShowDict kvs => Show (Store kvs) Source # 

Methods

showsPrec :: Int -> Store kvs -> ShowS #

show :: Store kvs -> String #

showList :: [Store kvs] -> ShowS #

type (</) k v = HasKey k v ~ AlreadyHasKey k Source #

'not elem key' constraint(ghc >= 7.8)

add :: k </ kvs => proxy k -> v -> Store kvs -> Store ((k := v) ': kvs) Source #

O(1) add key value pair to dictionary.

>>> let a = add (Proxy :: Proxy "foo") (12 :: Int) emptyStore
>>> a
Store {foo = 12 :: Int}
>>> add (Proxy :: Proxy "bar") "baz" a
Store {bar = "baz" :: [Char], foo = 12 :: Int}

mkDict :: Store kvs -> Dict kvs Source #

O(n) convert Store to Dictionary.

dictionary

data Dict kvs Source #

heterogeneous dictionary

get operation only allowed.

Instances

ShowDict kvs => Show (Dict kvs) Source # 

Methods

showsPrec :: Int -> Dict kvs -> ShowS #

show :: Dict kvs -> String #

showList :: [Dict kvs] -> ShowS #

class Member k v kvs | k kvs -> v Source #

Minimal complete definition

get'

Instances

(Member k v kvs, (~) GetResult (Index i) (Ix k ((:) (KV *) ((:=) * k' v') kvs)), KnownNat i) => Member k v ((:) (KV *) ((:=) * k' v') kvs) Source # 

Methods

get' :: proxy k -> Dict ((KV * ': (* := k') v') kvs) -> v

Member k v ((:) (KV *) ((:=) * k v) kvs) Source # 

Methods

get' :: proxy k -> Dict ((KV * ': (* := k) v) kvs) -> v

get :: Member k v kvs => proxy k -> Dict kvs -> v Source #

O(1) (>= ghc-7.8), O(n) (< ghc-7.8) get key from dictionary

>>> let d = mkDict $ add (Proxy :: Proxy "foo") 12 $ add (Proxy :: Proxy "bar") "baz" emptyStore
>>> get (Proxy :: Proxy "foo") d
12
>>> get (Proxy :: Proxy "bar") d
"baz"

types

class ShowDict kvs Source #

Minimal complete definition

showDict

Instances

ShowDict ([] (KV *)) Source # 

Methods

showDict :: Int -> Dict [KV *] -> [(String, String, TypeRep)]

(KnownSymbol k, Typeable * v, Show v, ShowDict kvs) => ShowDict ((:) (KV *) ((:=) * k v) kvs) Source # 

Methods

showDict :: Int -> Dict ((KV * ': (* := k) v) kvs) -> [(String, String, TypeRep)]

data KV v Source #

(kind) key-value pair

Constructors

Symbol := v 

Instances

(Member k v kvs, (~) GetResult (Index i) (Ix k ((:) (KV *) ((:=) * k' v') kvs)), KnownNat i) => Member k v ((:) (KV *) ((:=) * k' v') kvs) Source # 

Methods

get' :: proxy k -> Dict ((KV * ': (* := k') v') kvs) -> v

Member k v ((:) (KV *) ((:=) * k v) kvs) Source # 

Methods

get' :: proxy k -> Dict ((KV * ': (* := k) v) kvs) -> v

ShowDict ([] (KV *)) Source # 

Methods

showDict :: Int -> Dict [KV *] -> [(String, String, TypeRep)]

(KnownSymbol k, Typeable * v, Show v, ShowDict kvs) => ShowDict ((:) (KV *) ((:=) * k v) kvs) Source # 

Methods

showDict :: Int -> Dict ((KV * ': (* := k) v) kvs) -> [(String, String, TypeRep)]

type Members ([] (KV *)) prms Source # 
type Members ([] (KV *)) prms = ()
type Members ((:) (KV *) ((:=) * k v) kvs) prms Source # 
type Members ((:) (KV *) ((:=) * k v) kvs) prms = (Member k v prms, Members kvs prms)

convenient

type family Members (kvs :: [KV *]) (prms :: [KV *]) :: Constraint Source #

type family to constraint multi kvs.

Members ["foo" := Int, "bar" := Double] prms == (Member "foo" Int prms, Member "bar" Double prms)

Instances

type Members ([] (KV *)) prms Source # 
type Members ([] (KV *)) prms = ()
type Members ((:) (KV *) ((:=) * k v) kvs) prms Source # 
type Members ((:) (KV *) ((:=) * k v) kvs) prms = (Member k v prms, Members kvs prms)

pretty print type errors

data GetResult Source #

(kind) pretty print type error of get

used only >= ghc-7.8

> get (Proxy :: Proxy "b") (mkDict $ add (Proxy :: Proxy "a") "a" emptyStore)
Couldn't match type ‘'Key "b"’ with ‘'NotInDicrionary i’

Constructors

NotInDicrionary Nat 
Key Symbol 

data AddResult Source #

(kind) pretty print type error of add.

> add (Proxy :: Proxy "a") 12 $ add (Proxy :: Proxy "a") "a" emptyStore
Couldn't match type ‘'Dictionary’ with ‘'AlreadyHasKey "a"’