apiary-1.2.0: Simple and type safe web framework that can be automatically generate API documentation.

Safe HaskellNone
LanguageHaskell2010

Data.Apiary.Dict

Contents

Description

type sefe dictionaly.

Synopsis

Documentation

data Dict ks Source

empty :: Dict [] Source

empty Dict.

insert :: (KnownSymbol k, NotMember k kvs) => proxy k -> v -> Dict kvs -> Dict ((k := v) : kvs) Source

insert element.

ghci> :t insert (Proxy :: Proxy "foo") (12 :: Int) empty
insert (Proxy :: Proxy "foo") (12 :: Int) empty
  :: Dict '["foo" ':= Int]
ghci> :t insert (Proxy :: Proxy "bar") (0.5 :: Double) $ insert (Proxy :: Proxy "foo") (12 :: Int) empty
insert (Proxy :: Proxy "bar") (0.5 :: Double) $ insert (Proxy :: Proxy "foo") (12 :: Int) empty
  :: Dict '["bar" ':= Double, "foo" ':= Int]

ghc raise compile error when insert duplicated key(> ghc-7.8 only).

ghci> :t insert (Proxy :: Proxy "foo") (0.5 :: Double) $ insert (Proxy :: Proxy "foo") (12 :: Int) empty

<interactive>:1:1:
    Couldn't match type ‘'True’ with ‘'False’
    Expected type: 'False
      Actual type: Member' "foo" '["foo" ':= Int]
    In the expression: insert (Proxy :: Proxy "foo") (0.5 :: Double)
    In the expression:
      insert (Proxy :: Proxy "foo") (0.5 :: Double)
      $ insert (Proxy :: Proxy "foo") (12 :: Int) empty

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

Methods

get :: proxy k -> Dict kvs -> v Source

get value of key.

ghci> get (Proxy :: Proxy "bar") $ insert (Proxy :: Proxy "bar") (0.5 :: Double) $ insert (Proxy :: Proxy "foo") (12 :: Int) empty
0.5
ghci> get (Proxy :: Proxy "foo") $ insert (Proxy :: Proxy "bar") (0.5 :: Double) $ insert (Proxy :: Proxy "foo") (12 :: Int) empty
12

ghc raise compile error when key is not exists.

ghci> get (Proxy :: Proxy "baz") $ insert (Proxy :: Proxy "bar") (0.5 :: Double) $ insert (Proxy :: Proxy "foo") (12 :: Int) empty
<interactive>:15:1:
    No instance for (Member "baz" a0 '[]) arising from a use of ‘it’
    In the first argument of ‘print’, namely ‘it’
    In a stmt of an interactive GHCi command: print it

Instances

(KnownSymbol k, Member k v kvs) => Member k v ((:) Elem ((:=) * k' v') kvs) 
KnownSymbol k => Member k v ((:) Elem ((:=) * k v) kvs) 

key :: QuasiQuoter Source

construct string literal proxy.

[key|foo|] == (Proxy :: Proxy "foo")

types

data Elem Source

(kind) Dict element.

Constructors

forall a . Symbol := a 

Instances

(KnownSymbol k, Member k v kvs) => Member k v ((:) Elem ((:=) * k' v') kvs) 
KnownSymbol k => Member k v ((:) Elem ((:=) * k v) kvs) 
type Members ([] Elem) prms = () 
type Members ((:) Elem ((:=) * k v) kvs) prms = (Member k v prms, Members kvs prms) 

type NotMember k kvs = Member' k kvs ~ False Source

type family Member' k kvs :: Bool Source

type family version Member for NotMember constraint.

Equations

Member' k [] = False 
Member' k ((k := v) : kvs) = True 
Member' k' ((k := v) : kvs) = Member' k' kvs 

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 ([] Elem) prms = () 
type Members ((:) Elem ((:=) * k v) kvs) prms = (Member k v prms, Members kvs prms)