Îõ³h$SROž£      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢(C) 2013 Richard EisenbergBSD-style (see LICENSE) Ryan Scott experimental non-portableNone&'(-./2>ÀÇÉÔÖ×Ùèìòö&E%& singletons Similar to '*, but for two-parameter type constructors.' singletons: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 xs We can write: #Map (TyCon1 Succ) [Zero, Succ Zero]( singletonsÎAn "internal" defunctionalization symbol used primarily in the definition of *.3Note that this is only defined on GHC 8.6 or later.) singletonsÎAn "internal" defunctionalization symbol used primarily in the definition of *, as well as the ? instances for ', &, etc.3Note that this is only defined on GHC 8.6 or later.* singletons-An "internal" definition used primary in the - instance for +.0Note that this only defined on GHC 8.6 or later.+ singletonsWorkhorse for the 'Á, 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, ' et al.% were defined as separate data types., singletonsAn infix synonym for -- singletonsType level function application. singletonsSomething 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  >https://github.com/goldfirere/singletons/blob/master/README.mdREADME.Normal type-level arrows (->)3 can be converted into defunctionalization arrows (.) by the use of the +. family of types. (Refer to the Haddocks for 'ž 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 £ -> £ -> £*. One can turn it into something of kind £ . £ . £ by writing & (->), or something of kind £ -> £ . £ by writing ' ((->) t) (where t :: £)./ singletonsü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.0 singletonsA 0 wraps up a ? instance for explicit handling.3 singletonsThe singleton for 6Às. Informally, this is the singleton type for other singletons.6 singletonsA newtype around A.Since Aö is a type family, it cannot be used directly in type class instances. As one example, one cannot write a catch-all  instance SDecide k =>  TestEquality (A k). On the other hand, 6Ù is a perfectly ordinary data type, which means that it is quite possible to define an  instance SDecide k =>  TestEquality (6 k).9 singletonsAn 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 g.; singletonsThe ; 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 ;À instance to be well behaved, it should obey the following laws: > . = áD 9 (\x -> g x =) áD ¤ 4The final law can also be expressed in terms of the R pattern synonym: (\(R sing) -> R sing) áD ¤ < singletons6Get a base type from the promoted kind. For example,  Demote Bool will be the type Bool8. Rarely, the type and kind do not match. For example,  Demote Nat is Natural.= singletons-Convert a singleton to its unrefined version.> singletonsÈConvert an unrefined type to an existentially-quantified singleton type.? singletonsA ?‹ constraint is essentially an implicitly-passed singleton. If you need to satisfy this constraint with an explicit singleton, please see f or the A pattern synonym.@ singletons;Produce the singleton explicitly. You will likely need the ScopedTypeVariables0 extension to use this method the way you want.A singletons'The singleton kind-indexed type family.B singletons 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.C singletons=Convenient synonym to refer to the kind of a type variable: type KindOf (a :: k) = kR singletonsîAn explicitly bidirectional pattern synonym for going between a singleton and the corresponding demoted term.As an  expression5: this takes a singleton to its demoted (base) type.:t FromSing \@Bool!FromSing \@Bool :: Sing a -> BoolFromSing SFalseFalseAs a pattern8: It extracts a singleton from its demoted (base) type.  singAnd :: ¥ -> ¥ -> 9 ¥ singAnd (R singBool1) (R singBool2) = 9 (singBool1 %&& singBool2) instead of writing it with g: singAnd bool1 bool2 = g bool1 $ singBool1 -> g bool2 $ singBool2 -> 9 (singBool1 %&& singBool2) S singletonsÄ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.T singletonsGet an implicit singleton (a ? instance) from an explicit one.U singletonsAn infix synonym for V singletonsž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.^ singletonsThis is the inverse of V, and likewise for the other  unSingFun... functions.f singletonsÒConvenience function for creating a context with an implicit singleton available.g singletons Convert a normal datatype (like ¥Ä) to a singleton for that datatype, passing it into a continuation.h singletonsùA convenience function useful when we need to name a singleton value multiple times. Without this function, each use of @ä could potentially refer to a different singleton, and one has to use type signatures (often with ScopedTypeVariables#) to ensure that they are the same.i singletonsšA convenience function that names a singleton satisfying a certain property. If the singleton does not satisfy the property, then the function returns ¦Ø. The property is expressed in terms of the underlying representation of the singleton.j singletons7Allows creation of a singleton when a proxy is at hand.k singletons&Allows creation of a singleton when a proxy# is at hand.l singletonsöA convenience function that takes a type as input and demotes it to its value-level counterpart as output. This uses ; and ? behind the scenes, so l = = @.*This function is intended to be used with TypeApplications. For example: demote @TrueTrue#demote @(Nothing :: Maybe Ordering)Nothingw singletonsNote that this instance's >7 implementation crucially relies on the fact that the ; instances for k1 and k2 both satisfy the ; laws. If they don't, > might produce strange results!g singletonsThe original datatype singletonsFunction expecting a singletonê  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklêAU?@;<=>CB019:TSfgRjlkhi6783452/.'&%$#"! -,+*)(VWXYZ[\]^_`abcdePQNOLMJKHIFGDE  9 9 9 0 0 0,9 .0U9 (C) 2013 Richard EisenbergBSD-style (see LICENSE) Ryan Scott experimental non-portableNone'(./?ÉÔÖ×Ùìö+;x singletonsMembers of the x "kind" class support decidable equality. Instances of this class are generated alongside singleton definitions for datatypes that derive an § instance.y singletons>Compute a proof or disproof of equality, given two singletons.z singletonsA z about a type a0 is either a proof of existence or a proof that a cannot exist.{ singletons Witness for a| singletonsProof that no a exists} singletons,Because we can never create a value of type ", a function that type-checks at  a -> Void shows that objects of type a% can never exist. Thus, we say that a is }~ singletons&A suitable default implementation for ¨ that leverages x. singletons&A suitable default implementation for © that leverages x. xyz{|}~ xy}z{|~y4(C) 2017 Ryan ScottBSD-style (see LICENSE) Ryan Scott experimental non-portableNone./2>?ÀÉ×ÙòöGÁ‚ singletonsThe workhorse that powers ƒ. The only reason that ƒï` exists is to work around GHC's inability to put type families in the head of a quantified constraint (see  /https://gitlab.haskell.org/ghc/ghc/issues/14860this GHC issueÐ for more details on this point). In other words, GHC will not let you define ƒ like so: class (forall (z :: k). ª (A z)) => ƒ k  By replacing ª (A z) with  ShowSing' z;, we are able to avoid this restriction for the most part.The superclass of ƒ` is a bit peculiar: *class (forall (sing :: k -> Type). sing ~ A => ª (sing z)) => ƒ ` (z :: k) ßOne might wonder why this superclass is used instead of this seemingly more direct equivalent: class ª (A z) => ƒ ` (z :: k) óActually, these aren't equivalent! The latter's superclass mentions a type family in its head, and this gives GHC's constraint solver trouble when trying to match this superclass against other constraints. (See the discussion beginning at  =https://gitlab.haskell.org/ghc/ghc/-/issues/16365#note_189057Ì for more on this point). The former's superclass, on the other hand, does not£ mention a type family in its head, which allows it to match other constraints more easily. It may sound like a small difference, but it's the only reason that ƒÐ is able to work at all without a significant amount of additional workarounds.ËThe quantified superclass has one major downside. Although the head of the quantified superclass is more eager to match, which is usually a good thing, it can bite under certain circumstances. Because ª (sing z) will match a ª instance for any types sing :: k -> Type and z :: k , (where kù is a kind variable), it is possible for GHC's constraint solver to get into a situation where multiple instances match ª (sing z)À, and GHC will get confused as a result. Consider this example:  -- As in Data.Singletons newtype 6 :: forall k. k -> Type where 7 :: forall k (a :: k). { 8 :: A a } -> 6 a instance ƒ k => ª (6 (a :: k)) where « _ s = ¬: "WrapSing {unwrapSing = " . showsPrec 0 s . showChar '}' When typechecking the ª instance for 6), GHC must fill in a default definition ­ = defaultShow , where defaultShow :: ª (6 a) => 6 a -> ®Á. GHC's constraint solver has two possible ways to satisfy the ª (6 a) constraint for  defaultShow: 'The top-level instance declaration for ª (6 (a :: k)) itself, andª (sing (z :: k))= from the head of the quantified constraint arising from ƒ k.¨In practice, GHC will choose (2), as local quantified constraints shadow global constraints. This confuses GHC greatly, causing it to error out with an error akin to )Couldn't match type Sing with WrappedSing. See  1https://gitlab.haskell.org/ghc/ghc/-/issues/17934$ for a full diagnosis of the issue.ÆThe bad news is that because of GHC#17934, we have to manually define ­ (and ¯ ) in the ª instance for 6Ç in order to avoid confusing GHC's constraint solver. In other words,  deriving ª is a no-go for 6(. The good news is that situations like 6! are quite rare in the world of  singletons”@most of the time, ª# instances for singleton types do not have the shape ª (sing (z :: k)), where kÊ is a polymorphic kind variable. Rather, most such instances instantiate k to a specific kind (e.g., Bool, or [a]Ô), which means that they will not overlap the head of the quantified superclass in ƒ` as observed above.,Note that we define the single instance for ƒÆ` without the use of a quantified constraint in the instance context:  instance ª (A z) => ƒ ` (z :: k) We could“ define this instance with a quantified constraint in the instance context, and it would be equally as expressive. But it doesn't provide any additional functionality that the non-quantified version gives, so we opt for the non-quantified version, which is easier to read.ƒ singletons8In addition to the promoted and singled versions of the ª class that singletons-base< provides, it is also useful to be able to directly define ªæ instances for singleton types themselves. Doing so is almost entirely straightforward, as a derived ª‚ instance does 90 percent of the work. The last 10 percent”@getting the right instance context”@is a bit tricky, and that's where ƒ comes into play.óAs an example, let's consider the singleton type for lists. We want to write an instance with the following shape: instance ??? => ª (SList! (z :: [k])) where showsPrec p SNil$ = showString "SNil" showsPrec p (SCons€ sx sxs) = showParen (p > 10) $ showString "SCons " . showsPrec 11 sx . showSpace . showsPrec 11 sxs )To figure out what should go in place of ???=, observe that we require the type of each field to also be ª4 instances. In other words, we need something like (ª (A (a :: k)))4. But this isn't quite right, as the type variable a4 doesn't appear in the instance head. In fact, this aÐ type is really referring to an existentially quantified type variable in the SConsà constructor, so it doesn't make sense to try and use it like this. Luckily, the QuantifiedConstraintså language extension provides a solution to this problem. This lets you write a context of the form  (forall a. ª (A (a :: k)))/, which demands that there be an instance for ª (A (a :: k))" that is parametric in the use of a/. This lets us write something closer to this: instance (forall a. ª (A (a :: k))) => SList (A (z :: [k])) where ... The ƒ! class is a thin wrapper around  (forall a. ª (A (a :: k))). With ƒ/, our final instance declaration becomes this:  instance ƒ k => ª (SList (z :: [k])) where ... &In fact, this instance can be derived: deriving instance ƒ k => ª (SList (z :: [k])) $(Note that the actual definition of ƒÿ is slightly more complicated than what this documentation might suggest. For the full story, refer to the documentation for ƒ`.)When singling a derived ª instance,  singletons-th will also generate a ª5 instance for the corresponding singleton type using ƒ. In other words, if you give  singletons-th a derived ª8 instance, then you'll receive the following in return: A promoted (PShow ) instance A singled (SShow ) instanceA ª instance for the singleton typeWhat a bargain!‚ƒƒ‚(C) 2017 Ryan ScottBSD-style (see LICENSE) Ryan Scott experimental non-portableNone'(./>?ÀÁÂÉÔÖ×ÙìòöO:Œ singletons3Project the second element out of a dependent pair. singletons2Project the first element out of a dependent pair.Ž singletonsUnicode shorthand for . singletonsThe singleton type for ’.‘ singletonsUnicode shorthand for ’.’ singletonsA dependent pair.” singletons2Project the first element out of a dependent pair.• singletons3Project the second element out of a dependent pair.– singletonsÔProject the first element out of a dependent pair using continuation-passing style.— singletonsÕProject the second element out of a dependent pair using continuation-passing style.˜ singletons Map across a ’ value in a dependent fashion.™ singletonsZip two ’( values together in a dependent fashion.š singletons!Convert an uncurried function on ’ to a curried one. Together, š and ›Á witness an isomorphism such that the following identities hold: 'id1 :: forall a (b :: a ~> Type) (c :: ’0 a b ~> Type). (forall (p :: Sigma a b).  p -> c @% p) -> (forall (p :: Sigma a b).  p -> c  p) id1 f = › a b c (š a b -c f) id2 :: forall a (b :: a ~> Type) (c :: ’> a b ~> Type). (forall (x :: a) (sx :: Sing x) (y :: b  x). Sing (7 sx) -> Sing y -> c < (sx :&: y)) -> (forall (x :: a) (sx :: Sing x) (y :: b  x). Sing (7 sx) -> Sing y -> c  (sx :&: y)) id2 f = š a b c (› a b @c f) › singletonsConvert a curried function on ’ to an uncurried one. Together, š and ›: witness an isomorphism. (Refer to the documentation for š for more details.)Aˆ‰Š‹ŒŽ‘’“”•–—˜™š›’“‘AŽ”•Œ–—˜™š›‹‰Šˆ4“4°        !"#$%%&'()*+,-./01234567789:;<=>??@ABCDEFGHIJKLMNOPQRSTUVWFX3YZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª¦§«¬­¦®¯ °±²³´³µ³¶³·©¸³¹º%singletons-3.0-2Bb7RiSJovt5ASBQAp6wF9Data.Singletons.DecideData.SingletonsData.Singletons.ShowSingData.Singletons.Sigmabase Data.VoidVoid Data.ProxyProxyData.Type.EqualityRefl:~:@@@#@$$$@@@#@$$@@@#@$ ApplySym2 ApplySym1 ApplySym0~>@#@$$$~>@#@$$~>@#@$ KindOfSym1 KindOfSym0 SameKindSym2 SameKindSym1 SameKindSym0 DemoteSym1 DemoteSym0 SingFunction8 SingFunction7 SingFunction6 SingFunction5 SingFunction4 SingFunction3 SingFunction2 SingFunction1SLambda applySingTyCon8TyCon7TyCon6TyCon5TyCon4TyCon3TyCon2TyCon1ApplyTyConAux2ApplyTyConAux1 ApplyTyConTyCon@@Apply~>TyFun SingInstance UnwrapSing SWrappedSing SWrapSing sUnwrapSing WrappedSingWrapSing unwrapSingSomeSingSingKindDemotefromSingtoSingSingIsingSingSameKindKindOfSLambda8 applySing8SLambda7 applySing7SLambda6 applySing6SLambda5 applySing5SLambda4 applySing4SLambda3 applySing3SLambda2 applySing2FromSing singInstancesingFun1singFun2singFun3singFun4singFun5singFun6singFun7singFun8 unSingFun1 unSingFun2 unSingFun3 unSingFun4 unSingFun5 unSingFun6 unSingFun7 unSingFun8 withSingI withSomeSingwithSingsingThat singByProxy singByProxy#demote$fSingIWrappedSingWrapSing$fSingKindWrappedSing$fSingI->TyCon$fSingI->TyCon0$fSingI->TyCon1$fSingI->TyCon2$fSingI->TyCon3$fSingI->TyCon4$fSingI->TyCon5$fSingI->TyCon6 $fSingKind->SDecide%~DecisionProved DisprovedRefuteddecideEqualitydecideCoercion$fTestCoercionkWrappedSing$fTestEqualitykWrappedSing ShowSing'ShowSing $fShowSing'kz$fShowWrappedSing $fShowSingk$fShowSWrappedSingShowSingApply' ShowSingApply ShowApply' ShowApplySndSigmaFstSigmaSΣSSigma:%&:ΣSigma:&:fstSigmasndSigma projSigma1 projSigma2mapSigmazipSigma currySigma uncurrySigma$fSingISigma:&:$fShowApply'afx $fShowApplyaf $fShowSigma$fShowSingApply'afxz$fShowSingApplyaf $fShowSSigmaghc-prim GHC.TypesTypeGHC.BaseidBool GHC.MaybeNothing GHC.ClassesEq testEqualityData.Type.Coercion testCoercionGHC.ShowShow showsPrec showStringshowStringshowList