universe-some-1.2.1: 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

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

Instances

Instances details
DeriveUniverseSome Dec Source # 
Instance details

Defined in Data.Universe.Some.TH

DeriveUniverseSome Name Source # 
Instance details

Defined in Data.Universe.Some.TH

DeriveUniverseSome a => DeriveUniverseSome [a] Source # 
Instance details

Defined in Data.Universe.Some.TH

Methods

deriveUniverseSome :: [a] -> DecsQ Source #

DeriveUniverseSome a => DeriveUniverseSome (Q a) Source # 
Instance details

Defined in Data.Universe.Some.TH

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