| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Data.Some.GADT
Synopsis
- data Some (tag :: k -> Type) where
- mkSome :: forall {k} tag (a :: k). tag a -> Some tag
- withSome :: Some tag -> (forall (a :: k). tag a -> b) -> b
- withSomeM :: forall {k} m tag r. Monad m => m (Some tag) -> (forall (a :: k). tag a -> m r) -> m r
- mapSome :: (forall (x :: k). f x -> g x) -> Some f -> Some g
- foldSome :: (forall (a :: k). tag a -> b) -> Some tag -> b
- traverseSome :: forall {k} m f g. Functor m => (forall (a :: k). f a -> m (g a)) -> Some f -> m (Some g)
Documentation
data Some (tag :: k -> Type) where Source #
Existential. This is type is useful to hide GADTs' parameters.
>>>data Tag :: Type -> Type where TagInt :: Tag Int; TagBool :: Tag Bool>>>instance GShow Tag where gshowsPrec _ TagInt = showString "TagInt"; gshowsPrec _ TagBool = showString "TagBool">>>classify s = case s of "TagInt" -> [mkGReadResult TagInt]; "TagBool" -> [mkGReadResult TagBool]; _ -> []>>>instance GRead Tag where greadsPrec _ s = [ (r, rest) | (con, rest) <- lex s, r <- classify con ]
You can either use constructor:
>>>let x = Some TagInt>>>xSome TagInt
>>>case x of { Some TagInt -> "I"; Some TagBool -> "B" } :: String"I"
or you can use functions
>>>let y = mkSome TagBool>>>ySome TagBool
>>>withSome y $ \y' -> case y' of { TagInt -> "I"; TagBool -> "B" } :: String"B"
The implementation of mapSome is safe.
>>>let f :: Tag a -> Tag a; f TagInt = TagInt; f TagBool = TagBool>>>mapSome f ySome TagBool
but you can also use:
>>>withSome y (mkSome . f)Some TagBool
>>>read "Some TagBool" :: Some TagSome TagBool
>>>read "mkSome TagInt" :: Some TagSome TagInt
Instances
| Applicative m => Monoid (Some m) Source # | |
| Applicative m => Semigroup (Some m) Source # | |
| GRead f => Read (Some f) Source # | |
| GShow tag => Show (Some tag) Source # | |
| GNFData tag => NFData (Some tag) Source # | |
Defined in Data.Some.GADT | |
| GEq tag => Eq (Some tag) Source # | |
| GCompare tag => Ord (Some tag) Source # | |
Defined in Data.Some.GADT | |