Safe Haskell | None |
---|---|
Language | Haskell2010 |
type sefe dictionaly.
- data Dict ks
- empty :: Dict []
- insert :: NotMember k kvs => proxy k -> v -> Dict kvs -> Dict ((k := v) : kvs)
- class Member k v kvs | k kvs -> v where
- key :: QuasiQuoter
- data Elem = forall a . Symbol := a
- type NotMember k kvs = Member' k kvs ~ False
- type family Member' k kvs :: Bool
- type family Members kvs prms :: Constraint
Documentation
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
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
key :: QuasiQuoter Source
construct string literal proxy.
[key|foo|] == (SProxy :: SProxy "foo")
types
(kind) Dict element.