Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- class DeriveUniverseSome a where
- deriveUniverseSome :: a -> DecsQ
- universeSomeQ :: Name -> ExpQ
Documentation
class DeriveUniverseSome a where Source #
Derive the
instance.UniverseSome
n
>>>
:set -XGADTs -XTemplateHaskell -XStandaloneDeriving
>>>
import Data.Universe.Class (universe)
>>>
import Data.GADT.Show
>>>
data Tag b a where IntTag :: Tag b Int; BoolTag :: b -> Tag b Bool
>>>
deriving instance Show b => Show (Tag b a)
>>>
instance Show b => GShow (Tag b) where gshowsPrec = showsPrec
(data Unused
is to workaround bug in older GHCi)
>>> data Unused; $(deriveUniverseSome ''Tag)
>>>
universe :: [Some (Tag (Maybe Bool))]
[Some IntTag,Some (BoolTag Nothing),Some (BoolTag (Just False)),Some (BoolTag (Just True))]
deriveUniverseSome
variant taking a Name
guesses simple class constraints.
If you need more specific, you can specify them:
(Note: on older GHCs this will warn, as the instance definition doesn't have all methods defined).
>>>
data Tag b a where IntTag :: Tag b Int; BoolTag :: b -> Tag b Bool
>>>
deriving instance Show b => Show (Tag b a)
>>>
instance Show b => GShow (Tag b) where gshowsPrec = showsPrec
>>>
data Unused; $(deriveUniverseSome [d| instance Universe b => UniverseSome (Tag b) |])
...>>>
universe :: [Some (Tag (Maybe Bool))]
[Some IntTag,Some (BoolTag Nothing),Some (BoolTag (Just False)),Some (BoolTag (Just True))]
deriveUniverseSome :: a -> DecsQ Source #
Instances
DeriveUniverseSome Dec Source # | |
Defined in Data.Universe.Some.TH deriveUniverseSome :: Dec -> DecsQ Source # | |
DeriveUniverseSome Name Source # | |
Defined in Data.Universe.Some.TH deriveUniverseSome :: Name -> DecsQ Source # | |
DeriveUniverseSome a => DeriveUniverseSome [a] Source # | |
Defined in Data.Universe.Some.TH deriveUniverseSome :: [a] -> DecsQ Source # | |
DeriveUniverseSome a => DeriveUniverseSome (Q a) Source # | |
Defined in Data.Universe.Some.TH deriveUniverseSome :: Q a -> DecsQ Source # |
universeSomeQ :: Name -> ExpQ Source #
Derive the method for :: [
Some
tag]
>>>
:set -XGADTs -XTemplateHaskell -XStandaloneDeriving
>>>
import Data.GADT.Show
>>>
data Tag b a where IntTag :: Tag b Int; BoolTag :: b -> Tag b Bool
>>>
deriving instance Show b => Show (Tag b a)
>>>
instance Show b => GShow (Tag b) where gshowsPrec = showsPrec
>>>
$(universeSomeQ ''Tag) :: [Some (Tag Bool)]
[Some IntTag,Some (BoolTag False),Some (BoolTag True)]