apiary-1.1.1: 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 :: NotMember k kvs => proxy k -> v -> Dict kvs -> Dict ((k := v) : kvs) Source

insert element.

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

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

ghci> :t insert (SProxy :: SProxy "foo") (0.5 :: Double) $ insert (SProxy :: SProxy "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 (SProxy :: SProxy "foo") (0.5 :: Double)
    In the expression:
      insert (SProxy :: SProxy "foo") (0.5 :: Double)
      $ insert (SProxy :: SProxy "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 (SProxy :: SProxy "bar") $ insert (SProxy :: SProxy "bar") (0.5 :: Double) $ insert (SProxy :: SProxy "foo") (12 :: Int) empty
0.5
ghci> get (SProxy :: SProxy "foo") $ insert (SProxy :: SProxy "bar") (0.5 :: Double) $ insert (SProxy :: SProxy "foo") (12 :: Int) empty
12

ghc raise compile error when key is not exists.

ghci> get (SProxy :: SProxy "baz") $ insert (SProxy :: SProxy "bar") (0.5 :: Double) $ insert (SProxy :: SProxy "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

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

key :: QuasiQuoter Source

construct string literal proxy.

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

types

data Elem Source

(kind) Dict element.

Constructors

forall a . Symbol := a 

Instances

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