The singleton kind-indexed type family.
Modulesingletons-3.0.3Haskell2010
Data.Singletons
This module exports the basic definitions to use singletons. See also
Prelude.Singletons from the singletons-base
library, which re-exports this module alongside many singled definitions
based on the Prelude.
You may also want to read the original papers presenting this library, available at https://richarde.dev/papers/2012/singletons/paper.pdf and https://richarde.dev/papers/2014/promotion/promotion.pdf.
- 45 types
- 4 classes
- 46 values
- Packagesingletons-3.0.3
- Exports109
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceSingletons.hs
Main singleton definitions
9 declarationsThe singleton type for functions. Functions have somewhat special
treatment in singletons (see the Haddocks for (~>) for more information
about this), and as a result, the Sing instance for SLambda is one of the
only such instances defined in the singletons library rather than, say,
singletons-base.
An infix synonym for applySing
A SingI constraint is essentially an implicitly-passed singleton.
In contrast to the SingKind class, which is parameterized over data types promoted to the kind level, the SingI class is parameterized over values promoted to the type level. To explain this distinction another way, consider this code:
f = fromSing (sing @(T :: K))
Here, f uses methods from both SingI and SingKind. However, the shape
of each constraint is rather different: using sing requires a 'SingI T'
constraint, whereas using fromSing requires a 'SingKind K' constraint.
If you need to satisfy this constraint with an explicit singleton, please see withSingI or the Sing pattern synonym.
Instances10SingI, …
SingI a => SingI ('WrapSing s)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1). SingI a => SingI (f a), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon1 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2). (SingI a, SingI b) => SingI (f a b), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon2 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3). (SingI a, SingI b, SingI c) => SingI (f a b c), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon3 f)Defined in singletons-3.0.3 · Data.Singletons(SingI fst, SingI b) => SingI (a ':&: b)Defined in singletons-3.0.3 · Data.Singletons.Sigma(forall (a :: k1) (b :: k2) (c :: k3) (d :: k4). (SingI a, SingI b, SingI c, SingI d) => SingI (f a b c d), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon4 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3) (d :: k4) (e :: k5). (SingI a, SingI b, SingI c, SingI d, SingI e) => SingI (f a b c d e), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon5 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3) (d :: k4) (e :: k5) (f' :: k6). (SingI a, SingI b, SingI c, SingI d, SingI e, SingI f') => SingI (f a b c d e f'), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon6 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3) (d :: k4) (e :: k5) (f' :: k6) (g :: k7). (SingI a, SingI b, SingI c, SingI d, SingI e, SingI f', SingI g) => SingI (f a b c d e f' g), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon7 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3) (d :: k4) (e :: k5) (f' :: k6) (g :: k7) (h :: k8). (SingI a, SingI b, SingI c, SingI d, SingI e, SingI f', SingI g, SingI h) => SingI (f a b c d e f' g h), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon8 f)Defined in singletons-3.0.3 · Data.Singletons
The SingKind class is a kind class. It classifies all kinds for which singletons are defined. The class supports converting between a singleton type and the base (unrefined) type which it is built from.
For a SingKind instance to be well behaved, it should obey the following laws:
toSing . fromSing ≡ SomeSing
(\x -> withSomeSing x fromSing) ≡ id
The final law can also be expressed in terms of the FromSing pattern synonym:
(\(FromSing sing) -> FromSing sing) ≡ id
Associated types
type family Demote kGet a base type from the promoted kind. For example,
Demote Boolwill be the typeBool. Rarely, the type and kind do not match. For example,Demote NatisNatural.
Instances2SingKind
Working with singletons
26 declarationsConvenient synonym to refer to the kind of a type variable:
type KindOf (a :: k) = k
Force GHC to unify the kinds of a and b. Note that SameKind a b is
different from KindOf a ~ KindOf b in that the former makes the kinds
unify immediately, whereas the latter is a proposition that GHC considers
as possibly false.
A SingInstance wraps up a SingI instance for explicit handling.
Constructors
SingInstance :: SingI a => SingInstance a
An existentially-quantified singleton. This type is useful when you want a singleton type, but there is no way of knowing, at compile-time, what the type index will be. To make use of this type, you will generally have to use a pattern-match:
foo :: Bool -> ...
foo b = case toSing b of
SomeSing sb -> {- fancy dependently-typed code with sb -}An example like the one above may be easier to write using withSomeSing.
Get an implicit singleton (a SingI instance) from an explicit one.
An explicitly bidirectional pattern synonym for implicit singletons.
As an expression: Constructs a singleton Sing a given a
implicit singleton constraint SingI a.
As a pattern: Matches on an explicit Sing a witness bringing
an implicit SingI a constraint into scope.
Convenience function for creating a context with an implicit singleton available.
withSomeSing Convert a normal datatype (like Bool) to a singleton for that datatype, passing it into a continuation.
An explicitly bidirectional pattern synonym for going between a singleton and the corresponding demoted term.
As an expression: this takes a singleton to its demoted (base) type.
:t FromSing \@BoolFromSing \@Bool :: Sing a -> BoolFromSing SFalseFalse
As a pattern: It extracts a singleton from its demoted (base) type.
singAnd :: Bool -> Bool -> SomeSing Bool
singAnd (FromSing singBool1) (FromSing singBool2) =
SomeSing (singBool1 %&& singBool2)
instead of writing it with withSomeSing:
singAnd bool1 bool2 =
withSomeSing bool1 $ singBool1 ->
withSomeSing bool2 $ singBool2 ->
SomeSing (singBool1 %&& singBool2)
Allows creation of a singleton when a proxy is at hand.
Allows creation of a singleton for a unary type constructor when a proxy is at hand.
Allows creation of a singleton for a binary type constructor when a proxy is at hand.
A convenience function that takes a type as input and demotes it to its
value-level counterpart as output. This uses SingKind and SingI behind
the scenes, so demote = fromSing sing.
This function is intended to be used with TypeApplications. For example:
demote @TrueTrue
demote @(Nothing :: Maybe Ordering)Nothing
demote @(Just EQ)Just EQ
demote @'(True,EQ)(True,EQ)
A convenience function that takes a unary type constructor and its
argument as input, applies them, and demotes the result to its
value-level counterpart as output. This uses SingKind, SingI1, and
SingI behind the scenes, so demote1 = fromSing sing1.
This function is intended to be used with TypeApplications. For example:
demote1 @Just @EQJust EQ
demote1 @('(,) True) @EQ(True,EQ)
A convenience function that takes a binary type constructor and its
arguments as input, applies them, and demotes the result to its
value-level counterpart as output. This uses SingKind, SingI2, and
SingI behind the scenes, so demote2 = fromSing sing2.
This function is intended to be used with TypeApplications. For example:
demote2 @'(,) @True @EQ(True,EQ)
Allows creation of a singleton when a proxy# is at hand.
Allows creation of a singleton for a unary type constructor when a
proxy# is at hand.
Allows creation of a singleton for a binary type constructor when a
proxy# is at hand.
A convenience function useful when we need to name a singleton value
multiple times. Without this function, each use of sing could potentially
refer to a different singleton, and one has to use type signatures (often
with ScopedTypeVariables) to ensure that they are the same.
A convenience function useful when we need to name a singleton value for a
unary type constructor multiple times. Without this function, each use of
sing1 could potentially refer to a different singleton, and one has to use
type signatures (often with ScopedTypeVariables) to ensure that they are
the same.
A convenience function useful when we need to name a singleton value for a
binary type constructor multiple times. Without this function, each use of
sing1 could potentially refer to a different singleton, and one has to use
type signatures (often with ScopedTypeVariables) to ensure that they are
the same.
A convenience function that names a singleton satisfying a certain property. If the singleton does not satisfy the property, then the function returns Nothing. The property is expressed in terms of the underlying representation of the singleton.
A convenience function that names a singleton for a unary type constructor satisfying a certain property. If the singleton does not satisfy the property, then the function returns Nothing. The property is expressed in terms of the underlying representation of the singleton.
A convenience function that names a singleton for a binary type constructor satisfying a certain property. If the singleton does not satisfy the property, then the function returns Nothing. The property is expressed in terms of the underlying representation of the singleton.
WrappedSing
A newtype around Sing.
Since Sing is a type family, it cannot be used directly in type class
instances. As one example, one cannot write a catch-all
instance . On the other hand,
WrappedSing is a perfectly ordinary data type, which means that it is
quite possible to define an
SDecide k => TestEquality (Sing k)instance .SDecide k => TestEquality (WrappedSing k)
Constructors
WrapSing :: Sing a -> WrappedSing aunwrapSing :: Sing a
Instances7TestCoercion, TestEquality, Show, SingKind, SingI, Sing, …
SDecide k => TestCoercion WrappedSingDefined in singletons-3.0.3 · Data.Singletons.Decide · orphanSDecide k => TestEquality WrappedSingDefined in singletons-3.0.3 · Data.Singletons.Decide · orphanShowSing k => Show (WrappedSing a)Defined in singletons-3.0.3 · Data.Singletons.ShowSing · orphanSingKind (WrappedSing a)Defined in singletons-3.0.3 · Data.SingletonsSingI a => SingI ('WrapSing s)Defined in singletons-3.0.3 · Data.Singletonstype Sing = SWrappedSingDefined in singletons-3.0.3 · Data.Singletonstype Demote (WrappedSing a) = WrappedSing aDefined in singletons-3.0.3 · Data.Singletons
The singleton for WrappedSings. Informally, this is the singleton type for other singletons.
Constructors
SWrapSing :: Sing a -> SWrappedSing a1sUnwrapSing :: Sing a
Instances1Show
ShowSing k => Show (SWrappedSing ws)Defined in singletons-3.0.3 · Data.Singletons.ShowSing · orphan
Equations
UnwrapSing ('WrapSing s) = s
Aside from being a data type to hang instances off of, WrappedSing has another purpose as a general-purpose mechanism for allowing one to write code that uses singletons of other singletons. For instance, suppose you had the following data type:
data T :: Type -> Type where
MkT :: forall a (x :: a). Sing x -> F a -> T a
A naïve attempt at defining a singleton for T would look something like
this:
data ST :: forall a. T a -> Type where
SMkT :: forall a (x :: a) (sx :: Sing x) (f :: F a).
Sing sx -> Sing f -> ST (MkT sx f)
But there is a problem here: what exactly is Sing sx? If x were True,
for instance, then sx would be STrue, but it's not clear what
Sing should be. One could define STrueSSBool to be the singleton of
SBools, but in order to be thorough, one would have to generate a singleton
for every singleton type out there. Plus, it's not clear when to stop. Should
we also generate SSSBool, SSSSBool, etc.?
Instead, WrappedSing and its singleton SWrappedSing provide a way to talk about singletons of other arbitrary singletons without the need to generate a bazillion instances. For reference, here is the definition of SWrappedSing:
newtype SWrappedSing :: forall k (a :: k). WrappedSing a -> Type where
SWrapSing :: forall k (a :: k) (ws :: WrappedSing a).
{ sUnwrapSing :: Sing a } -> SWrappedSing ws
type instance Sing @(WrappedSing a) = SWrappedSing
SWrappedSing is a bit of an unusual singleton in that its field is a
singleton for Sing @k, not WrappedSing @k. But that's exactly the
point—a singleton of a singleton contains as much type information as the
underlying singleton itself, so we can get away with just Sing @k.
As an example of this in action, here is how you would define the singleton
for the earlier T type:
data ST :: forall a. T a -> Type where
SMkT :: forall a (x :: a) (sx :: Sing x) (f :: F a).
Sing (WrapSing sx) -> Sing f -> ST (MkT sx f)
With this technique, we won't need anything like SSBool in order to
instantiate x with True. Instead, the field of type
Sing (WrapSing sx) will simply be a newtype around SBool. In general,
you'll need n layers of WrapSing if you wish to single a singleton n
times.
Note that this is not the only possible way to define a singleton for T.
An alternative approach that does not make use of singletons-of-singletons is
discussed at some length
here.
Due to the technical limitations of this approach, however, we do not use it
in singletons at the moment, instead favoring the
slightly-clunkier-but-more-reliable WrappedSing approach.
Defunctionalization
Representation of the kind of a type-level function. The difference between term-level arrows and this type-level arrow is that at the term level applications can be unsaturated, whereas at the type level all applications have to be fully saturated.
Instances16SingKind, SingI, Apply, Sing, Demote, …
(SingKind k1, SingKind k2) => SingKind (k1 ~> k2)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1). SingI a => SingI (f a), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon1 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2). (SingI a, SingI b) => SingI (f a b), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon2 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3). (SingI a, SingI b, SingI c) => SingI (f a b c), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon3 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3) (d :: k4). (SingI a, SingI b, SingI c, SingI d) => SingI (f a b c d), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon4 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3) (d :: k4) (e :: k5). (SingI a, SingI b, SingI c, SingI d, SingI e) => SingI (f a b c d e), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon5 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3) (d :: k4) (e :: k5) (f' :: k6). (SingI a, SingI b, SingI c, SingI d, SingI e, SingI f') => SingI (f a b c d e f'), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon6 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3) (d :: k4) (e :: k5) (f' :: k6) (g :: k7). (SingI a, SingI b, SingI c, SingI d, SingI e, SingI f', SingI g) => SingI (f a b c d e f' g), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon7 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3) (d :: k4) (e :: k5) (f' :: k6) (g :: k7) (h :: k8). (SingI a, SingI b, SingI c, SingI d, SingI e, SingI f', SingI g, SingI h) => SingI (f a b c d e f' g h), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon8 f)Defined in singletons-3.0.3 · Data.Singletonstype Apply ApplySym0 f = ApplySym1 fDefined in singletons-3.0.3 · Data.Singletonstype Apply SameKindSym0 x = SameKindSym1 xDefined in singletons-3.0.3 · Data.Singletonstype Apply (@@@#@$) f = (@@@#@$$) fDefined in singletons-3.0.3 · Data.Singletonstype Apply (TyCon f) x = ApplyTyCon f @@ xDefined in singletons-3.0.3 · Data.Singletonstype Apply (~>@#@$) x = (~>@#@$$) xDefined in singletons-3.0.3 · Data.Singletonstype Sing = SLambdaDefined in singletons-3.0.3 · Data.Singletonstype Demote (k1 ~> k2) = Demote k1 -> Demote k2Defined in singletons-3.0.3 · Data.Singletons
Something of kind a ~> b is a defunctionalized type function that is
not necessarily generative or injective. Defunctionalized type functions
(also called "defunctionalization symbols") can be partially applied, even
if the original type function cannot be. For more information on how this
works, see the "Promotion and partial application" section of the
README.
The singleton for things of kind a ~> b is SLambda. SLambda values
can be constructed in one of two ways:
With the
singFun*family of combinators (e.g., singFun1). For example, if you have:
type Id :: a -> a
sId :: Sing a -> Sing (Id a)
Then you can construct a value of type Sing @(a ~> a) (that is,
SLambda @a @a like so:
sIdFun :: Sing @(a ~> a) IdSym0
sIdFun = singFun1 @IdSym0 sId
Where IdSym0 :: a ~> a is the defunctionlized version of Id.
Using the SingI class. For example,
sing @IdSym0is another way of definingsIdFunabove. Thesingletons-thlibrary automatically generates SingI instances for defunctionalization symbols such asIdSym0.
Normal type-level arrows (->) can be converted into defunctionalization
arrows (~>) by the use of the TyCon family of types. (Refer to the
Haddocks for TyCon1 to see an example of this in practice.) For this
reason, we do not make an effort to define defunctionalization symbols for
most type constructors of kind a -> b, as they can be used in
defunctionalized settings by simply applying TyCon{N} with an appropriate
N.
This includes the (->) type constructor itself, which is of kind
Type -> Type -> Type. One can turn it into something of kind
Type ~> Type ~> Type by writing TyCon2 (->), or something of
kind Type -> Type ~> Type by writing TyCon1 ((->) t)
(where t :: Type).
Wrapper for converting the normal type-level arrow into a ~>. For example, given:
data Nat = Zero | Succ Nat
type family Map (a :: a ~> b) (a :: [a]) :: [b]
Map f '[] = '[]
Map f (x ': xs) = Apply f x ': Map f xsWe can write:
Map (TyCon1 Succ) [Zero, Succ Zero]Similar to TyCon1, but for two-parameter type constructors.
Type level function application
Instances13Apply, …
type Apply ApplySym0 f = ApplySym1 fDefined in singletons-3.0.3 · Data.Singletonstype Apply DemoteSym0 x = Demote xDefined in singletons-3.0.3 · Data.Singletonstype Apply KindOfSym0 x = KindOf xDefined in singletons-3.0.3 · Data.Singletonstype Apply SameKindSym0 x = SameKindSym1 xDefined in singletons-3.0.3 · Data.Singletonstype Apply (@@@#@$) f = (@@@#@$$) fDefined in singletons-3.0.3 · Data.Singletonstype Apply (ApplySym1 f) x = Apply f xDefined in singletons-3.0.3 · Data.Singletonstype Apply (ApplyTyConAux1 f) x = f xDefined in singletons-3.0.3 · Data.Singletonstype Apply (ApplyTyConAux2 f) x = TyCon (f x)Defined in singletons-3.0.3 · Data.Singletonstype Apply (SameKindSym1 x) y = SameKind x yDefined in singletons-3.0.3 · Data.Singletonstype Apply (TyCon f) x = ApplyTyCon f @@ xDefined in singletons-3.0.3 · Data.Singletonstype Apply (~>@#@$) x = (~>@#@$$) xDefined in singletons-3.0.3 · Data.Singletonstype Apply ((@@@#@$$) f) x = f @@ xDefined in singletons-3.0.3 · Data.Singletonstype Apply ((~>@#@$$) x) y = x ~> yDefined in singletons-3.0.3 · Data.Singletons
An infix synonym for Apply
Workhorse for the TyCon1, etc., types. This can be used directly
in place of any of the TyConN types, but it will work only with
monomorphic types. When GHC#14645 is fixed, this should fully supersede
the TyConN types.
Note that this is only defined on GHC 8.6 or later. Prior to GHC 8.6, TyCon1 et al. were defined as separate data types.
Instances9SingI, Apply, …
(forall (a :: k1). SingI a => SingI (f a), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon1 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2). (SingI a, SingI b) => SingI (f a b), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon2 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3). (SingI a, SingI b, SingI c) => SingI (f a b c), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon3 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3) (d :: k4). (SingI a, SingI b, SingI c, SingI d) => SingI (f a b c d), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon4 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3) (d :: k4) (e :: k5). (SingI a, SingI b, SingI c, SingI d, SingI e) => SingI (f a b c d e), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon5 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3) (d :: k4) (e :: k5) (f' :: k6). (SingI a, SingI b, SingI c, SingI d, SingI e, SingI f') => SingI (f a b c d e f'), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon6 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3) (d :: k4) (e :: k5) (f' :: k6) (g :: k7). (SingI a, SingI b, SingI c, SingI d, SingI e, SingI f', SingI g) => SingI (f a b c d e f' g), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon7 f)Defined in singletons-3.0.3 · Data.Singletons(forall (a :: k1) (b :: k2) (c :: k3) (d :: k4) (e :: k5) (f' :: k6) (g :: k7) (h :: k8). (SingI a, SingI b, SingI c, SingI d, SingI e, SingI f', SingI g, SingI h) => SingI (f a b c d e f' g h), ApplyTyCon ~ ApplyTyConAux1) => SingI (TyCon8 f)Defined in singletons-3.0.3 · Data.Singletonstype Apply (TyCon f) x = ApplyTyCon f @@ xDefined in singletons-3.0.3 · Data.Singletons
An "internal" defunctionalization symbol used primarily in the definition of ApplyTyCon, as well as the SingI instances for TyCon1, TyCon2, etc.
Note that this is only defined on GHC 8.6 or later.
Instances1Apply
type Apply (ApplyTyConAux1 f) x = f xDefined in singletons-3.0.3 · Data.Singletons
An "internal" defunctionalization symbol used primarily in the definition of ApplyTyCon.
Note that this is only defined on GHC 8.6 or later.
Instances1Apply
type Apply (ApplyTyConAux2 f) x = TyCon (f x)Defined in singletons-3.0.3 · Data.Singletons
Defunctionalized singletons
When calling a higher-order singleton function, you need to use a
singFun... function to wrap it. See singFun1.
Use this function when passing a function on singletons as a higher-order function. You will need visible type application to get this to work. For example:
falses = sMap (singFun1 @NotSym0 sNot)
(STrue `SCons` STrue `SCons` SNil)There are a family of singFun... functions, keyed by the number
of parameters of the function.
This is the inverse of singFun1, and likewise for the other
unSingFun... functions.
SLambda{2...8} are explicitly bidirectional pattern synonyms for
defunctionalized singletons (Sing (f :: k ~> k' ~> k'')).
As constructors: Same as singFun{2..8}. For example, one can turn a
binary function on singletons sTake :: SingFunction2 TakeSym0 into a
defunctionalized singleton Sing (TakeSym :: Nat ~> [a] ~> [a]):
>>> import Data.List.Singletons
>>> :set -XTypeApplications
>>>
>>> :t SLambda2
SLambda2 :: SingFunction2 f -> Sing f
>>> :t SLambda2 @TakeSym0
SLambda2 :: SingFunction2 TakeSym0 -> Sing TakeSym0
>>> :t SLambda2 @TakeSym0 sTake
SLambda2 :: Sing TakeSym0
This is useful for functions on singletons that expect a defunctionalized
singleton as an argument, such as sZipWith :: SingFunction3 ZipWithSym0:
sZipWith :: Sing (f :: a ~> b ~> c) -> Sing (xs :: [a]) -> Sing (ys :: [b]) -> Sing (ZipWith f xs ys :: [c])
sZipWith (SLambda2 @TakeSym0 sTake) :: Sing (xs :: [Nat]) -> Sing (ys :: [[a]]) -> Sing (ZipWith TakeSym0 xs ys :: [[a]])
As patterns: Same as unSingFun{2..8}. Gets a binary term-level
Haskell function on singletons
Sing (x :: k) -> Sing (y :: k') -> Sing (f @@ x @@ y)
from a defunctionalised Sing f. Alternatively, as a record field accessor:
applySing2 :: Sing (f :: k ~> k' ~> k'') -> SingFunction2 f
These type synonyms are exported only to improve error messages; users should not have to mention them.
type SingFunction7 (f :: a1 ~> (a2 ~> (a3 ~> (a4 ~> (a5 ~> (a6 ~> (a7 ~> b))))))) = forall (t1 :: a1) (t2 :: a2) (t3 :: a3) (t4 :: a4) (t5 :: a5) (t6 :: a6) (t7 :: a7). Sing t1 -> Sing t2 -> Sing t3 -> Sing t4 -> Sing t5 -> Sing t6 -> Sing t7 -> Sing (((((((f @@ t1) @@ t2) @@ t3) @@ t4) @@ t5) @@ t6) @@ t7)type SingFunction8 (f :: a1 ~> (a2 ~> (a3 ~> (a4 ~> (a5 ~> (a6 ~> (a7 ~> (a8 ~> b)))))))) = forall (t1 :: a1) (t2 :: a2) (t3 :: a3) (t4 :: a4) (t5 :: a5) (t6 :: a6) (t7 :: a7) (t8 :: a8). Sing t1 -> Sing t2 -> Sing t3 -> Sing t4 -> Sing t5 -> Sing t6 -> Sing t7 -> Sing t8 -> Sing ((((((((f @@ t1) @@ t2) @@ t3) @@ t4) @@ t5) @@ t6) @@ t7) @@ t8)Auxiliary functions
1 declarationProxy is a type that holds no data, but has a phantom parameter of arbitrary type (or even kind). Its use is to provide type information, even though there is no value available of that type (or it may be too costly to create one).
Historically, Proxy :: Proxy a is a safer alternative to the
undefined :: a idiom.
Proxy :: Proxy (Void, Int -> Int)Proxy
Proxy can even hold types of higher kinds,
Proxy :: Proxy EitherProxy
Proxy :: Proxy FunctorProxy
Proxy :: Proxy complicatedStructureProxy
Instances27Generic1, Monad, Functor, Applicative, Foldable, Traversable, …
Generic1 ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.GenericsMonad ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyFunctor ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyApplicative ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyFoldable ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.FoldableTraversable ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.TraversableAlternative ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyMonadPlus ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyMonadZip ProxyDefined in base-4.20.2.0 · Control.Monad.ZipEq1 ProxyDefined in base-4.20.2.0 · Data.Functor.ClassesOrd1 ProxyDefined in base-4.20.2.0 · Data.Functor.ClassesRead1 ProxyDefined in base-4.20.2.0 · Data.Functor.ClassesShow1 ProxyDefined in base-4.20.2.0 · Data.Functor.ClassesContravariant ProxyDefined in base-4.20.2.0 · Data.Functor.ContravariantBounded (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyEnum (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyEq (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyData t => Data (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataOrd (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyRead (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyShow (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyIx (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyGeneric (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsSemigroup (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyMonoid (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxytype Rep (Proxy t) = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"Proxy"
"GHC.Internal.Data.Proxy"
"ghc-internal"
'False) (C1 ('MetaCons"Proxy"
'PrefixI 'False) U1)type Rep1 Proxy = D1 ('MetaDataDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics"Proxy"
"GHC.Internal.Data.Proxy"
"ghc-internal"
'False) (C1 ('MetaCons"Proxy"
'PrefixI 'False) U1)
Defunctionalization symbols
16 declarationsInstances1Apply
type Apply DemoteSym0 x = Demote xDefined in singletons-3.0.3 · Data.Singletons
Instances1Apply
type Apply SameKindSym0 x = SameKindSym1 xDefined in singletons-3.0.3 · Data.Singletons
Instances1Apply
type Apply (SameKindSym1 x) y = SameKind x yDefined in singletons-3.0.3 · Data.Singletons
Instances1Apply
type Apply KindOfSym0 x = KindOf xDefined in singletons-3.0.3 · Data.Singletons