Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- type SomeDict = SomeDictOf Proxy
- data SomeDictOf (f :: k -> Type) (c :: k -> Constraint) where
- SomeDictOf :: c a => f a -> SomeDictOf f c
- someDict :: forall a c. c a => SomeDict c
- fromDict :: forall a c. Dict (c a) -> SomeDict c
- withSomeDictOf :: SomeDictOf f c -> (forall a. c a => f a -> r) -> r
- mapSomeDictOf :: (forall a. c a => f a -> g a) -> SomeDictOf f c -> SomeDictOf g c
- forgetContents :: forall f c. Functor f => SomeDictOf f c -> f (SomeDictOf Proxy c)
- module Data.Functor.Identity
- module Data.Proxy
- module Data.Constraint
Documentation
type SomeDict = SomeDictOf Proxy Source #
In the case where you only need evidence that the dictionary exists,
then you can use this type. By carrying a Proxy
instead of a real
value, we can summon these up whenever we have an instance of the type in
question.
Since: 0.1.0.0
data SomeDictOf (f :: k -> Type) (c :: k -> Constraint) where Source #
A datatype that carries evidence of type class membership for some type, along with a datatype indexed by that type. This is confusing, so let's look at some examples.
The alias
uses SomeDict
clazzProxy
for the datatype index. This means
that the wrapper is a
, and you know that the type
Proxy
:: Proxy
aa
has an instance of clazz a
. We can construct a value
showSomeDict :: SomeDictOf Identity Show showSomeDict = SomeDict (Identity 3 :: Identity Int)
A value of
contains SomeDict
Show
Proxy
value. When you pattern
match on the SomeDict
, you know that the given
has an instance of Proxy
:: Proxy
aShow
.
For the most part, this isn't useful,
Since: 0.1.0.0
SomeDictOf :: c a => f a -> SomeDictOf f c |
someDict :: forall a c. c a => SomeDict c Source #
Construct a SomeDict
with the type in question. Use with
TypeApplications
.
Example:
showDict :: SomeDict Show
showDict = someDict Int
entityDict :: SomeDict PersistEntity
entityDict = someDict
User
Since: 0.1.0.0
fromDict :: forall a c. Dict (c a) -> SomeDict c Source #
Construct a SomeDict
based on a Dict
from the Data.Constraint module.
Since: 0.1.0.0
withSomeDictOf :: SomeDictOf f c -> (forall a. c a => f a -> r) -> r Source #
Unpack a SomeDictOf
and attain access to the evidence that the
underlying type satisfies the instance in question.
Since: 0.1.0.0
mapSomeDictOf :: (forall a. c a => f a -> g a) -> SomeDictOf f c -> SomeDictOf g c Source #
Transform the type index used in the SomeDictOf
. The provided function is
unable to inspect the type, but you will have the class operations available
to it.
Example:
provideMempty ;: SomeDictOf Proxy Monoid -> SomeDictOf Identity Monoid provideMempty = mapSomeDictOf (proxy -> Identity mempty)
Since: 0.1.0.0
forgetContents :: forall f c. Functor f => SomeDictOf f c -> f (SomeDictOf Proxy c) Source #
Not really sure what this might be useful for.
Examples:
shows :: SomeDictOf [] Show shows = SomeDictOf [True, False, True] forgotten :: [SomeDictOf Proxy Show] forgotten = forgetContents show main = do forM forgotten $ (SomeDictOf Proxy) -> do print 10
The above program should output 10 three times.
Since: 0.1.0.0
Re-exports
module Data.Functor.Identity
module Data.Proxy
module Data.Constraint