Safe Haskell | None |
---|

- newtype Object = Object (Map TypeRep Dynamic)
- class Typeable a => KeyType a where
- type ValType a :: *

- type Member kt = Lens Object Object (Maybe (ValType kt)) (Maybe (ValType kt))
- empty :: Object
- mkMember :: forall kt. (KeyType kt, Typeable (ValType kt)) => kt -> Member kt
- mkMemberWithDef :: forall kt. (KeyType kt, Typeable (ValType kt)) => kt -> ValType kt -> Member kt

# Documentation

A basic object type that can contain values of different types.

mkMember :: forall kt. (KeyType kt, Typeable (ValType kt)) => kt -> Member ktSource

Given a key type, create a `Member`

`Lens`

labeled by the key.
Here's an example of creating a price tag for objects.

`>>>`

`data Price = Price deriving (Show, Typeable)`

`>>>`

`instance KeyType Price where type ValType Price = Integer`

`>>>`

`let price :: Member Price; price = mkMember Price;`

`>>>`

`let x = set price (Just 120) empty`

`>>>`

Nothing`view price empty`

`>>>`

Just 120`view price x`

mkMemberWithDef :: forall kt. (KeyType kt, Typeable (ValType kt)) => kt -> ValType kt -> Member ktSource

Create a `Member`

`Lens`

with a default value.
Here's a price tag for objects with default value.

`>>>`

`data Price = Price deriving (Show, Typeable)`

`>>>`

`instance KeyType Price where type ValType Price = Integer`

`>>>`

`let price :: Member Price; price = mkMemberWithDef Price 10;`

`>>>`

`let x = set price (Just 120) empty`

`>>>`

Just 10`view price empty`

`>>>`

Just 120`view price x`