Safe Haskell | None |
---|---|
Language | Haskell2010 |
- class EqSing1 f where
- class EqSing2 f where
- class EqSing1 f => OrdSing1 f where
- class EqSing2 f => OrdSing2 f where
- class ShowSing2 f where
- class ReadSing2 f where
- class HashableSing1 f where
- class HashableSing2 f where
- class ToJSONSing1 f where
- class ToJSONSing2 f where
- class FromJSONSing1 f where
- class FromJSONSing2 f where
- class ShowKind k where
- class ReadKind k where
- class HashableKind k where
- class ToJSONKind k where
- class FromJSONKind k where
- class ToJSONKeyKind k where
- class FromJSONKeyKind k where
- newtype Applied1 f a = Applied1 {
- getApplied1 :: Apply f a
- newtype Applied2 f a b = Applied2 {
- getApplied2 :: Apply (Apply f a) b
- newtype Applied3 f a b c = Applied3 {
- getApplied3 :: Apply (Apply (Apply f a) b) c
- data SomeSingWith1 k f where
- SomeSingWith1 :: forall a f. Sing a -> f a -> SomeSingWith1 k f
- type family SomeSingWith1' (f :: k -> Type) :: Type where ...
- data SomeSingWith2 k j f where
- SomeSingWith2 :: forall a b f. Sing a -> Sing b -> f a b -> SomeSingWith2 k j f
- type family SomeSingWith2' (f :: k -> j -> Type) :: Type where ...
- data SingWith1 k f a where
- newtype ClassySomeSing kproxy = ClassySomeSing {
- getClassySomeSing :: SomeSing kproxy
- class EqApplied1 f where
- class HashableApplied1 f where
- class ToJSONApplied1 f where
- class FromJSONApplied1 f where
- showKind :: forall a. ShowKind k => Sing a -> String
- readMaybeKind :: ReadKind kproxy => String -> Maybe (SomeSing kproxy)
- eqSome :: SEq kproxy => SomeSing kproxy -> SomeSing kproxy -> Bool
- compareSome :: SOrd kproxy => SomeSing kproxy -> SomeSing kproxy -> Ordering
Singleton Classes
These are singleton variants of the commonly used classes from base
,
hashable
, and aeson
. These variants work on higher-kinded types instead
of on ground types. For example, if you wrote the following:
data MyType = MyInt | MyBool | MyChar $(genSingletons [''MyType]) type family Interpret m where Interpret 'MyInt = Int Interpret 'MyChar = Char Interpret 'MyBool = Bool newtype MyValue x = MyValue { getMyValue :: Interpret x }
You could then write MyValue
instances for all of the classes that in this
module that end in Sing1
. For example:
instance EqSing1 MyValue where eqSing1 x a b = case x of SMyInt -> a == b SMyChar -> a == b SMyBool -> a == b
For our example MyValue
type, the EqSing1
instance is trivial. We simply
pattern match on the singleton and then do the same thing in each case. This
kind of pattern matching ends up happening any time our universe
interpreter maps to types that all have Eq
instances. Since writing this
out is tedious, we can instead use a template haskell function provided in
the Data.Case.Enumerate
module:
instance EqSing1 MyValue where eqSing1 x a b $(enumerateConstructors 'x ''MyValue =<< [|a == b|])
Instances for the other classes here can be written similarly.
class EqSing1 f => OrdSing1 f where Source #
compareSing1 :: Sing a -> f a -> f a -> Ordering Source #
class HashableSing1 f where Source #
HashableApplied1 k f => HashableSing1 k (Applied1 k f) Source # | |
class HashableSing2 f where Source #
class ToJSONSing1 f where Source #
toJSONSing1 :: Sing a -> f a -> Value Source #
ToJSONApplied1 k f => ToJSONSing1 k (Applied1 k f) Source # | |
class ToJSONSing2 f where Source #
class FromJSONSing1 f where Source #
FromJSONApplied1 k f => FromJSONSing1 k (Applied1 k f) Source # | |
class FromJSONSing2 f where Source #
Kind classes
These are kind classes. They express that something is true for all
singletons of a particular kind. Note that these are different from the
kind classes provided in the singletons
library itself. The methods
in those classes (SOrd
,SEnum
,etc.) work entirely on singletons. Here,
the methods also work with normal data types.
Notice that classes like EqKind
and OrdKind
have been omitted from
this library. The reason is that that functions that would be provided by
these can be trivially recovered by demoting the results of methods in SEq
and SOrd
.
These methods in these classes all have defaults that involve demoting the singleton and using the corresponding method from the normal typeclass.
class HashableKind k where Source #
class ToJSONKind k where Source #
class FromJSONKind k where Source #
class ToJSONKeyKind k where Source #
class FromJSONKeyKind k where Source #
Data types
Applied1 | |
|
FromJSONApplied1 k f => FromJSONSing1 k (Applied1 k f) Source # | |
ToJSONApplied1 k f => ToJSONSing1 k (Applied1 k f) Source # | |
HashableApplied1 k f => HashableSing1 k (Applied1 k f) Source # | |
EqApplied1 k f => EqSing1 k (Applied1 k f) Source # | |
Eq (Apply k * f a) => Eq (Applied1 k f a) Source # | |
Ord (Apply k * f a) => Ord (Applied1 k f a) Source # | |
Read (Apply k * f a) => Read (Applied1 k f a) Source # | |
Show (Apply k * f a) => Show (Applied1 k f a) Source # | |
Hashable (Apply k * f a) => Hashable (Applied1 k f a) Source # | |
ToJSON (Apply k * f a) => ToJSON (Applied1 k f a) Source # | |
FromJSON (Apply k * f a) => FromJSON (Applied1 k f a) Source # | |
data SomeSingWith1 k f where Source #
SomeSingWith1 :: forall a f. Sing a -> f a -> SomeSingWith1 k f |
(EqSing1 kproxy f, SDecide kproxy) => Eq (SomeSingWith1 kproxy f) Source # | |
(HashableKind k, HashableSing1 k f) => Hashable (SomeSingWith1 k f) Source # | |
type family SomeSingWith1' (f :: k -> Type) :: Type where ... Source #
SomeSingWith1' (f :: k -> Type) = SomeSingWith1 k f |
data SomeSingWith2 k j f where Source #
SomeSingWith2 :: forall a b f. Sing a -> Sing b -> f a b -> SomeSingWith2 k j f |
(SDecide kproxy1, SDecide kproxy2, EqSing2 kproxy2 kproxy1 f) => Eq (SomeSingWith2 kproxy1 kproxy2 f) Source # | |
(ReadKind k, ReadKind j, ReadSing2 j k f) => Read (SomeSingWith2 k j f) Source # | |
(ShowKind kproxy1, ShowKind kproxy2, ShowSing2 kproxy2 kproxy1 f) => Show (SomeSingWith2 kproxy1 kproxy2 f) Source # | |
(ToJSONKind kproxy1, ToJSONKind kproxy2, ToJSONSing2 kproxy2 kproxy1 f) => ToJSON (SomeSingWith2 kproxy1 kproxy2 f) Source # | |
(FromJSONKind k, FromJSONKind j, FromJSONSing2 j k f) => FromJSON (SomeSingWith2 k j f) Source # | |
type family SomeSingWith2' (f :: k -> j -> Type) :: Type where ... Source #
SomeSingWith2' (f :: k -> j -> Type) = SomeSingWith2 k j f |
newtype ClassySomeSing kproxy Source #
This is a wrapper for SomeSing
that provides common typeclass instances
for it. This can be helpful when you want to use Data.Set
with SomeSing
.
ClassySomeSing | |
|
SEq kproxy => Eq (ClassySomeSing kproxy) Source # | |
SOrd kproxy => Ord (ClassySomeSing kproxy) Source # | |
Classes for Applied
These are additional classes used to provide instances for Applied1
.
If you have a defunctionalized typeclass that provides produces types
in the category hask, you can use this. Instances will often look like
this:
data Thing = ... type family ToType (x :: Thing) :: Type where ... instance EqApplied1 ToTypeSym0 where eqApplied1 _ x (Applied a) (Applied b) = $(enumerateConstructors 'x ''Thing =<< [|a == b|])
class EqApplied1 f where Source #
class HashableApplied1 f where Source #
class ToJSONApplied1 f where Source #
class FromJSONApplied1 f where Source #