| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Singletons.Dict
Synopsis
- mkTotalDictGetter :: Name -> Name -> Q [Dec]
- mkPartialDictGetter :: Name -> Name -> Q [Dec]
Documentation
Generates Dict getters for the promoted nullary data constructors corresponding to
a singletons-like type.
All the promoted data constructors must be instances of the given type class.
The names of the getters result from the concatenation of:
- the camel-cased name of the base type,
- the name of the type class,
- the "
Dict" keyword, - the "A" suffix, for the contextual getter.
Example:
Given this type:
data Example = Foo | Bar | Baz
and the corresponding singletons-like type:
data SExample (example :: Example) where
SFoo :: SExample 'Foo
SBar :: SExample 'Bar
SBaz :: SExample 'Baz
this line:
$(mkTotalDictGetter ''SExample ''Typeable)
generates those getters:
exampleTypeableDict :: SExample example ->Dict(Typeableexample) exampleTypeableDict sing = case sing of SFoo ->DictSBar ->DictSBaz ->DictexampleTypeableDictA ::Applicativef => SExample example -> f (Dict(Typeableexample)) exampleTypeableDictA sing = case sing of SFoo ->pureDictSBar ->pureDictSBaz ->pureDict
Generates Dict getters for the promoted nullary data constructors corresponding to
a singletons-like type.
Not all the promoted data constructors must be instances of the given type class.
The name of the getters results from the concatenation of:
- the camel-cased name of the base type,
- the name of the type class,
- the "
Dict" keyword, - the "A" suffix, for the contextual getter.
Example:
Given this type:
data Example = Foo | Bar | Baz
the corresponding singletons-like type:
data SExample (example :: Example) where
SFoo :: SExample 'Foo
SBar :: SExample 'Bar
SBaz :: SExample 'Baz
and this type class and instance:
class IsBar (a :: k) where instance IsBar 'Bar where
this line:
$(mkPartialDictGetter ''SExample ''IsBar)
generates those getters:
exampleIsBarDict :: SExample example ->Maybe(Dict(IsBar example)) exampleIsBarDict sing = case sing of SFoo ->NothingSBar ->JustDictSBaz ->NothingexampleIsBarDictA ::Applicativef => SExample example -> f (Maybe(Dict(IsBar example))) exampleIsBarDictA sing = case sing of SFoo ->pureNothingSBar ->pure(JustDict) SBaz ->pureNothing