web-routing-0.6.0: simple routing library

Safe HaskellNone
LanguageHaskell2010

Network.Routing.Dict

Contents

Synopsis

store

data Store kvs Source

Instances

ShowDict kvs => Show (Store kvs) 

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) 

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) 
Member k v ((:) (KV *) ((:=) * k v) kvs) 

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 *)) 
(KnownSymbol k, Typeable * v, Show v, ShowDict kvs) => ShowDict ((:) (KV *) ((:=) * k v) kvs) 

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) 
Member k v ((:) (KV *) ((:=) * k v) kvs) 
ShowDict ([] (KV *)) 
(KnownSymbol k, Typeable * v, Show v, ShowDict kvs) => ShowDict ((:) (KV *) ((:=) * k v) kvs) 
type Members ([] (KV *)) prms = () 
type Members ((:) (KV *) ((:=) * k v) kvs) prms = (Member k v prms, Members kvs prms) 

convenient

type family Members kvs prms :: 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 = () 
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"’