Safe Haskell | None |
---|---|
Language | Haskell2010 |
- class EqSing1 f where
- class EqSing2 f where
- class EqSing1 f => OrdSing1 f where
- compareSing1 :: Sing a -> f a -> f a -> Ordering
- class EqSing2 f => OrdSing2 f where
- compareSing2 :: Sing a -> Sing b -> f a b -> f a b -> Ordering
- class HashableSing1 f where
- hashWithSaltSing1 :: Sing a -> Int -> f a -> Int
- class HashableSing2 f where
- hashWithSaltSing2 :: Sing a -> Sing b -> Int -> f a b -> Int
- class ToJSONSing1 f where
- toJSONSing1 :: Sing a -> f a -> Value
- class ToJSONSing2 f where
- toJSONSing2 :: Sing a -> Sing b -> f a b -> Value
- class FromJSONSing1 f where
- parseJSONSing1 :: Sing a -> Value -> Parser (f a)
- class FromJSONSing2 f where
- parseJSONSing2 :: Sing a -> Sing b -> Value -> Parser (f a b)
- class (kproxy ~ KProxy) => ShowKind kproxy where
- showsPrecKind :: Int -> Sing (x :: a) -> ShowS
- class (kproxy ~ KProxy) => ReadKind kproxy where
- readsPrecKind :: Int -> ReadS (SomeSing kproxy)
- class (kproxy ~ KProxy) => HashableKind kproxy where
- hashWithSaltKind :: Int -> Sing (x :: a) -> Int
- class (kproxy ~ KProxy) => ToJSONKind kproxy where
- toJSONKind :: Sing (x :: a) -> Value
- class (kproxy ~ KProxy) => FromJSONKind kproxy where
- parseJSONKind :: Value -> Parser (SomeSing kproxy)
- class (kproxy ~ KProxy) => ToJSONKeyKind kproxy where
- toJSONKeyKind :: Sing (x :: a) -> Text
- class (kproxy ~ KProxy) => FromJSONKeyKind kproxy where
- parseJSONKeyKind :: Text -> Parser (SomeSing kproxy)
- 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 kproxy f where
- SomeSingWith1 :: Sing a -> f a -> SomeSingWith1 KProxy f
- type SomeSingWith1' = SomeSingWith1 KProxy
- data SomeSingWith2 kproxy1 kproxy2 f where
- SomeSingWith2 :: Sing a -> Sing b -> f a b -> SomeSingWith2 KProxy KProxy f
- type SomeSingWith2' = SomeSingWith2 KProxy KProxy
- data SingWith1 kproxy f a where
- newtype ClassySomeSing kproxy = ClassySomeSing {
- getClassySomeSing :: SomeSing kproxy
- class EqApplied1 f where
- eqApplied1 :: proxy f -> Sing a -> Apply f a -> Apply f a -> Bool
- class HashableApplied1 f where
- hashWithSaltApplied1 :: proxy f -> Sing a -> Int -> Apply f a -> Int
- class ToJSONApplied1 f where
- toJSONApplied1 :: proxy f -> Sing a -> Apply f a -> Value
- class FromJSONApplied1 f where
- parseJSONApplied1 :: proxy f -> Sing a -> Value -> Parser (Apply f a)
- showKind :: forall kproxy a. ShowKind kproxy => 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.
EqApplied1 k f => EqSing1 k (Applied1 k f) Source |
class EqSing2 f => OrdSing2 f where Source
compareSing2 :: Sing a -> Sing b -> f a b -> f a b -> Ordering Source
class HashableSing1 f where Source
hashWithSaltSing1 :: Sing a -> Int -> f a -> Int 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
toJSONSing2 :: Sing a -> Sing b -> f a b -> Value Source
class FromJSONSing1 f where Source
parseJSONSing1 :: Sing a -> Value -> Parser (f a) 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 (kproxy ~ KProxy) => ShowKind kproxy where Source
Nothing
showsPrecKind :: Int -> Sing (x :: a) -> ShowS Source
class (kproxy ~ KProxy) => ReadKind kproxy where Source
Nothing
readsPrecKind :: Int -> ReadS (SomeSing kproxy) Source
class (kproxy ~ KProxy) => HashableKind kproxy where Source
Nothing
hashWithSaltKind :: Int -> Sing (x :: a) -> Int Source
class (kproxy ~ KProxy) => ToJSONKind kproxy where Source
Nothing
toJSONKind :: Sing (x :: a) -> Value Source
class (kproxy ~ KProxy) => FromJSONKind kproxy where Source
parseJSONKind :: Value -> Parser (SomeSing kproxy) Source
class (kproxy ~ KProxy) => ToJSONKeyKind kproxy where Source
Nothing
toJSONKeyKind :: Sing (x :: a) -> Text Source
class (kproxy ~ KProxy) => FromJSONKeyKind kproxy where Source
Nothing
parseJSONKeyKind :: Text -> Parser (SomeSing kproxy) 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 |
data SomeSingWith1 kproxy f where Source
SomeSingWith1 :: Sing a -> f a -> SomeSingWith1 KProxy f |
(EqSing1 k f, SDecide k kproxy) => Eq (SomeSingWith1 k kproxy f) Source | |
(HashableKind k kproxy1, HashableSing1 k f) => Hashable (SomeSingWith1 k kproxy1 f) Source |
type SomeSingWith1' = SomeSingWith1 KProxy Source
data SomeSingWith2 kproxy1 kproxy2 f where Source
SomeSingWith2 :: Sing a -> Sing b -> f a b -> SomeSingWith2 KProxy KProxy f |
(ToJSONKind k kproxy1, ToJSONKind k1 kproxy2, ToJSONSing2 k k1 f) => ToJSON (SomeSingWith2 k k kproxy1 kproxy2 f) Source | |
(FromJSONKind k kproxy1, FromJSONKind k1 kproxy2, FromJSONSing2 k k1 f) => FromJSON (SomeSingWith2 k k kproxy1 kproxy2 f) Source |
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 k kproxy => Eq (ClassySomeSing k kproxy) Source | |
SOrd k kproxy => Ord (ClassySomeSing k 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) :: * 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
toJSONApplied1 :: proxy f -> Sing a -> Apply f a -> Value Source
class FromJSONApplied1 f where Source