universe-some-1.2: Universe instances for Some from some

Safe HaskellSafe
LanguageHaskell2010

Data.Universe.Some.TH

Synopsis

Documentation

class DeriveUniverseSome a where Source #

Derive the UniverseSome n instance.

>>> :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
>>> ; 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:

>>> ; 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))]

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)]