singletons-base
A promoted and singled version of the base library
http://www.github.com/goldfirere/singletons
| LTS Haskell 24.16: | 3.4 |
| Stackage Nightly 2025-10-24: | 3.5 |
| Latest on Hackage: | 3.5 |
singletons-base-3.5@sha256:e9aa6f9eb84d6590bb8aebb038226b9dfd743d4ab288e6f5a844138da472859b,7581Module documentation for 3.5
- Control
- Control.Applicative
- Control.Monad
- Control.Monad.Fail
- Control.Monad.Singletons
- Control.Monad.Zip
- Data
- Data.Bool
- Data.Either
- Data.Eq
- Data.Foldable
- Data.Function
- Data.Functor
- Data.Functor.Compose
- Data.Functor.Const
- Data.Functor.Identity
- Data.Functor.Product
- Data.Functor.Singletons
- Data.Functor.Sum
- Data.List
- Data.List.NonEmpty
- Data.List.Singletons
- Data.Maybe
- Data.Monoid
- Data.Ord
- Data.Proxy
- Data.Semigroup
- Data.Singletons
- Data.String
- Data.Traversable
- Data.Tuple
- Data.Void
- GHC
- GHC.TypeLits
- Prelude
- Text
- Text.Show
singletons-base
singletons-base uses singletons-th to define promoted and singled
functions from the @base@ library, including the Prelude. This library was
originally presented in
Dependently Typed Programming with Singletons,
published at the Haskell Symposium, 2012. See also
the paper published at Haskell Symposium, 2014,
which describes how promotion works in greater detail.
WARNING: singletons-base defines orphan instances for Sing, SingKind, etc.
for common types such as Bool, [], Maybe, etc. If you define
instances of these types in your code, you will likely not be able to use
that code with singletons-base.
singletons-base uses code that relies on bleeding-edge GHC language
extensions. As such, singletons-base only supports the latest major version
of GHC (currently GHC 9.12). For more information,
consult the singletons
README.
You may also be interested in the following related libraries:
- The
singletonslibrary is a small, foundational library that defines basic singleton-related types and definitions. - The
singletons-thlibrary defines Template Haskell functionality that allows promotion of term-level functions to type-level equivalents and singling functions to dependently typed equivalents.
Changes
Changelog for the singletons-base project
3.5 [2024.12.11]
-
Require building with GHC 9.12.
-
Remove the use of a custom
Setup.hsscript. This script has now been replaced with acabalcode generator As such,singletons-basenow requires the use ofCabal-3.8or later in order to build. -
The types of
sError,sErrorWithoutStackTrace, andsUndefinedare now less polymorphic than they were before:-sError :: forall a (str :: Symbol). HasCallStack => Sing str -> a +sError :: forall a (str :: Symbol). HasCallStack => Sing str -> Sing (Error @a str) -sErrorWithoutStackTrace :: forall a (str :: Symbol). Sing str -> a +sErrorWithoutStackTrace :: forall a (str :: Symbol). Sing str -> Sing (ErrorWithoutStackTrace @a str) -sUndefined :: forall a. HasCallStack => a +sUndefined :: forall a. HasCallStack => Sing (Undefined @a)This is because the old type signatures were too polymorphic, and they required ad hoc special casing in
singletons-thin order to make them work in generated code. The more specific type signatures that these functions now have improve type inference and avoid the need for special casing. If you truly need the full polymorphism of the old type signatures, useerror,errorWithoutStackTrace, orundefinedinstead. -
The kinds of
PAlternative(and other classes insingletons-basethat are parameterized over a higher-kinded type variable) are less polymorphic than they were before:-type PAlternative :: (k -> Type) -> Constraint +type PAlternative :: (Type -> Type) -> Constraint -type PMonadZip :: (k -> Type) -> Constraint +type PMonadZip :: (Type -> Type) -> Constraint -type PMonadPlus :: (k -> Type) -> Constraint +type PMonadPlus :: (Type -> Type) -> ConstraintSimilarly, the kinds of defunctionalization symbols for these classes (e.g.,
EmptySym0and(<|>@#@$)) now useType -> Typeinstead ofk -> Type. The fact that these were kind-polymorphic to begin with was an oversight, as these could not be used whenkwas instantiated to any other kind besidesType. -
The kinds in the
PFunctorinstance forComposeare less polymorphic than they were before:-instance PFunctor (Compose (f :: k -> Type) (g :: Type -> k)) +instance PFunctor (Compose (f :: Type -> Type) (g :: Type -> Type))Similarly for the
PFoldable,PTraversable,PApplicative, andPAlternativeinstances forCompose. The fact that these instances were so polymorphic to begin with was an oversight, as these instances could not be used whenkwas instantiated to any other kind besidesType. -
The kinds of
AsumandMsumare less polymorphic than they were before:-type Asum :: forall {j} {k} (t :: k -> Type) (f :: j -> k) (a :: j). t (f a) -> f a +type Asum :: forall (t :: Type -> Type) (f :: Type -> Type) (a :: Type). t (f a) -> f a -type Msum :: forall {j} {k} (t :: k -> Type) (m :: j -> k) (a :: j). t (m a) -> m a +type Msum :: forall (t :: Type -> Type) (m :: Type -> Type) (a :: Type). t (m a) -> m aSimilarly, the kinds of defunctionalization symbols for these definitions (e.g.,
AsumSym0andMSym0) are less polymorphic. The fact that these were kind-polymorphic to begin with was an oversight, as these definitions could not be used whenjorkwas instantiated to any other kind besidesType. -
Define hand-written
Singinstances such that they explicitly match on their types on the left-hand sides (e.g., definetype instance Sing @Symbol = SSymbolinstead oftype instance Sing = SSymbol. Doing so will makesingletons-basefuture-proof once GHC#23515 is fixed.
3.4 [2024.05.12]
- Require building with GHC 9.10.
3.3 [2023.10.13]
-
Require building with GHC 9.8.
-
All singleton types with
SEqorSOrdinstances now haveEqorOrdinstances of the form:instance Eq (SExample a) where _ == _ = True instance Ord (SExample a) where compare _ _ = EQ -
Define
{P,S}Eqand{P,S}Ordinstances forSum,Product, andCompose. -
Define
TestEqualityandTestOrderinginstances forSSum,SProduct, andSCompose.
3.2 [2023.03.12]
-
Require building with GHC 9.6.
-
The kinds of the promoted
ErrorandErrorWithoutStackTracefunctions have been monomorphized toSymbol. A previous release generalized the kinds of these arguments to allow passing arguments besidesSymbols, but this change introduces ambiguity in derived code whenOverloadedStrings is enabled. See #89 for the full story.If you were relying on the previous, kind-polymorphic behavior of
Error, you can instead use the newData.Singletons.Base.PolyErrormodule that providesPolyError, a version ofErrorwith a kind-polymorphic argument. -
Data.Ord.SingletonsandData.Singletons.Base.THno longer define athenCmp :: Ordering -> Ordering -> Orderingfunction, as this is not something that has ever existed inbase. The existence of athenCmpfunction was solely motivated by the code generated by derivedOrdinstances, butsingletons-basenow uses(<>) @Orderinginstead. -
GHC.TypeLits.Singletonsnow re-exports theSChar,SNat, andSSymbolsingleton types offered byGHC.TypeLitsinbase-4.18.0.0rather than defining its own versions. The versions ofSChar,SNat, andSSymboloffered byGHC.TypeLitsare nearly identical, minus some minor cosmetic changes (e.g.,GHC.TypeLitsdefines pattern synonyms forSNatet a. instead of data constructors). -
GHC.TypeLits.Singletonsnow re-exports theSSymbolpattern synonym fromGHC.TypeLits.GHC.TypeLits.Singletonsalso continues to exportSSymfor backwards compatibility. -
Prelude.Singletonsnow re-exportsLiftA2andsLiftA2, mirroring the fact thatPreludenow re-exportsliftA2inbase-4.18.0.0. -
Provide
TestEqualityandTestCoercioninstances forSNat,SSymbol, andSChar`.
3.1.1 [2022.08.23]
- Require building with GHC 9.4.
3.1 [2021.10.30]
-
Require building with GHC 9.2.
-
singletons-basenow supports type-levelChars, a feature added in GHC 9.2. In particular:- Promoting and singling character literal expressions (e.g.,
f = 'a') is now supported. Promoting (but not singling) character patterns (e.g.,g 'a' = ()) is also supported. GHC.TypeLits.Singletonsnow offers singled versions of theConsSymbol,UnconsSymbol,CharToNat, andNatToChartype families that were introduced toGHC.TypeLitsin GHC 9.2.Text.Show.Singletonsnow makes use of type-levelChars, a feature added in GHC 9.2. As a result, there is no longer any need for theSChartype synonym, so it has been removed.- The
PShowandSShowinstances forSymbolnow display escape characters properly rather than returning the inputSymbolunchanged.
- Promoting and singling character literal expressions (e.g.,
-
In GHC 9.2,
Natis now a synonym forNatural. As a result, the bogusNum,Eq,Ord,Enum, andShowinstances forNatinGHC.TypeLits.Singletonshave been removed, as they have replaced by the corresponding instances forNatural. -
Add
Data.Functor.{Compose,Product,Sum}.Singletons. -
The types of various entities in
Data.Functor.Const.SingletonsandData.Proxy.Singletonshave been tweaked slightly such that their specificities match their term-level counterparts:-SConst :: forall {k} {a} {b :: k} (x :: a). Sing x -> Sing ('Const @a @b x) +SConst :: forall {k} a (b :: k) (x :: a). Sing x -> Sing ('Const @a @b x) -type ConstSym0 :: forall k a (b :: k). a ~> Const a b +type ConstSym0 :: forall {k} a (b :: k). a ~> Const a b -type ConstSym1 :: forall k a (b :: k). a -> Const a b +type ConstSym1 :: forall {k} a (b :: k). a -> Const a b -type ProxySym0 :: forall k (t :: k). Proxy t +type ProxySym0 :: forall {k} (t :: k). Proxy t -
Define instances of
SingI1andSingI2when possible.
3.0 [2021.03.12]
-
The
singletonslibrary has been split into three libraries:- The new
singletonslibrary is now a minimal library that only providesData.Singletons,Data.Singletons.Decide,Data.Singletons.Sigma, andData.Singletons.ShowSing(if compiled with GHC 8.6 or later).singletonsnow supports building GHCs back to GHC 8.0, as well as GHCJS. - The
singletons-thlibrary defines Template Haskell functionality for promoting and singling term-level definitions, but but nothing else. This library continues to require the latest stable release of GHC. - The
singletons-baselibrary defines promoted and singled versions of definitions from thebaselibrary, including thePrelude. This library continues to require the latest stable release of GHC.
Consult the changelogs for
singletonsandsingletons-thfor changes specific to those libraries. For more information on this split, see the relevant GitHub discussion. - The new
-
Require building with GHC 9.0.
-
The modules in
singletons-basehave been renamed to better reflect the modules frombasefrom which they take inspiration. In particular, the following module renamings have been applied:Data.Singletons.CustomStar->Data.Singletons.Base.CustomStarData.Singletons.Prelude->Prelude.SingletonsData.Singletons.Prelude.Applicative->Control.Applicative.SingletonsData.Singletons.Prelude.Bool->Data.Bool.SingletonsData.Singletons.Prelude.Const->Data.Functor.Const.SingletonsData.Singletons.Prelude.Either->Data.Either.SingletonsData.Singletons.Prelude.Enum->Data.Singletons.Base.EnumData.Singletons.Prelude.Eq->Data.Eq.SingletonsData.Singletons.Prelude.Foldable->Data.Foldable.SingletonsData.Singletons.Prelude.Function->Data.Function.SingletonsData.Singletons.Prelude.Functor->Data.Functor.Const.SingletonsData.Singletons.Prelude.Identity->Data.Functor.Identity.SingletonsData.Singletons.Prelude.IsString->Data.String.SingletonsData.Singletons.Prelude.Ord->Data.Ord.SingletonsData.Singletons.Prelude.List->Data.List.SingletonsData.Singletons.Prelude.List.NonEmpty->Data.List.NonEmpty.SingletonsData.Singletons.Prelude.Maybe->Data.Maybe.SingletonsData.Singletons.Prelude.Monad->Control.Monad.SingletonsData.Singletons.Prelude.Monad.Fail->Control.Monad.Fail.SingletonsData.Singletons.Prelude.Monad.Zip->Control.Monad.Zip.SingletonsData.Singletons.Prelude.Monoid->Data.Monoid.SingletonsData.Singletons.Prelude.Proxy->Data.Proxy.SingletonsData.Singletons.Prelude.Semigroup->Data.Semigroup.SingletonsData.Singletons.Prelude.Show->Data.Show.SingletonsData.Singletons.Prelude.Traversable->Data.Traversable.SingletonsData.Singletons.Prelude.Tuple->Data.Tuple.SingletonsData.Singletons.Prelude.Void->Data.Void.SingletonsData.Singletons.TH->Data.Singletons.Base.THData.Singletons.TypeError->Data.Singletons.Base.TypeErrorData.Singletons.TypeLits->GHC.TypeLits.SingletonsData.Singletons.TypeRepTYPE->Data.Singletons.Base.TypeRepTYPE
Note that modules that do not correspond to any particular module in
basenow have the prefixData.Singletons.Base.*. This includesData.Singletons.Base.Enum, a special module that exists to provide a home for theSuccandPredpromoted type families that is separate fromPrelude.Singletons(which exports everything fromPEnumexceptSuccandPred). This is done in an effort to make importingPrelude.Singletonsless likely to induce name clashes with code that works over unary natural numbers, which often use the names “Succ” and “Pred”. -
An effort has been made to make the API of
Prelude.Singletonsmore closely mirror that of thePreludeinbase. As a result,Prelude.Singletonsnow exports some different functions than it used to. In particular, it now exports the following:Until/sUntil/UntilSym{N}type (++@#@$$$)type (.@#@$$$$)FlipSym3type (!!)/(%!!)/type (!!@#@{$})Length/sLength/LengthSym{N}DropWhile/sDropWhileLookupSym{N}Unzip3Sym{N}
Prelude.Singletonsalso used to export some things that were not exported by thePrelude. Accordingly, these exports have been removed fromPrelude.Singletons. They are:(^)/(%^)/type (^@#@{$}). Although thePreludedoes define a function named(^), it is more general than the one defined insingletons-base, which only works onNats. ImportGHC.TypeLits.Singletonsif you wish to use theNat-specific versions.DefaultEq, which has no counterpart in thePrelude. ImportData.Eq.Singletonsif you wish to use this.bool_, which has no counterpart in thePrelude. ImportData.Bool.Singletonsif you wish to use this.
-
Two previously public-facing modules—
Data.Singletons.Prelude.BaseandData.Singletons.Prelude.Num—have been turned into internal modules. The contents of these modules are re-exported fromPrelude.Singletons, so that can be used instead. -
Due to the
singletonspackage split, theEq,Ord, etc. instances forSomeSingare no longer provided in theData.Singletonsmodule in thesingletonslibrary. Instead, they are now provided in a newData.Singletons.Base.SomeSingmodule, which definesEq,Ord, etc. instances forSomeSingas orphans. -
The
PEqclass no longer usesDefaultEqas its default implementation for(==).DefaultEq, despite its name, is actually not a suitable implementation for(==)for a good majority of singleton types (see the discussion in this GitHub issue for more information).(==)’s default is now defined in terms of(/=), just like its term-level counterpart in theEqclass. -
Since
base-4.15.0.0now deprecatesData.Singletons.Option(in anticipation of its removal in a future version ofbase), this library no longer offers a singleton type forOption. Accordingly, theoption_function has also been removed.