HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulesome-1.0.6Haskell2010

Data.Some

An existential type.

The constructor is exported only on GHC-8 and later.

  • 1 type
  • 6 values
  • Packagesome-1.0.6
  • Exports8
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceSome.hs
newtypenewtype Some (tag :: k -> Type)
#

Existential. This is type is useful to hide GADTs' parameters.

Example4 expressions
data Tag :: Type -> Type where TagInt :: Tag Int; TagBool :: Tag Boolinstance 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 PatternSynonyms (available with GHC >= 8.0)

Example2 expressions
let x = Some TagIntxSome TagInt
Example1 expression
case x of { Some TagInt -> "I"; Some TagBool -> "B" } :: String"I"

or you can use functions

Example2 expressions
let y = mkSome TagBoolySome TagBool
Example1 expression
withSome y $ \y' -> case y' of { TagInt -> "I"; TagBool -> "B" } :: String"B"

The implementation of mapSome is safe.

Example2 expressions
let f :: Tag a -> Tag a; f TagInt = TagInt; f TagBool = TagBoolmapSome f ySome TagBool

but you can also use:

Example1 expression
withSome y (mkSome . f)Some TagBool
Example1 expression
read "Some TagBool" :: Some TagSome TagBool
Example1 expression
read "mkSome TagInt" :: Some TagSome TagInt
Instances7Eq, Ord, Read, Show, Semigroup, Monoid, …
patternpattern Some :: tag a -> Some tag
#
valuewithSome :: Some tag -> (forall (a :: k). tag a -> b) -> b
#

Eliminator.

valuemapSome :: (forall (t :: k). f t -> g t) -> Some f -> Some g
#

Map over argument.