Safe Haskell | None |
---|---|
Language | Haskell2010 |
type sefe dictionaly.
- data Dict ks
- empty :: Dict []
- insert :: (KnownSymbol k, 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 :: (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
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
(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
(kind) Dict element.