Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- class Contravariant f => Selectable f where
- class Divisible f => JSONObjectSerializer f where
- writeField :: Text -> (forall jsonSerializer. JSONSerializer jsonSerializer => jsonSerializer a) -> f a
- class Divisible f => JSONTupleSerializer f where
- writeItem :: (forall jsonSerializer. JSONSerializer jsonSerializer => jsonSerializer a) -> f a
- class Selectable f => JSONSerializer f where
- serializeObject :: Text -> (forall objSerializer. JSONObjectSerializer objSerializer => objSerializer a) -> f a
- serializeDictionary :: Foldable t => (forall jsonSerializer. JSONSerializer jsonSerializer => jsonSerializer a) -> f (t (Text, a))
- serializeText :: f Text
- serializeTextConstant :: Text -> f a
- serializeNull :: f any
- serializeNumber :: f Scientific
- serializeBool :: f Bool
- serializeTuple :: (forall tupleSerializer. JSONTupleSerializer tupleSerializer => tupleSerializer a) -> f a
- serializeArray :: ToJSON a => f [a]
- class ToJSON v where
- toJSON :: JSONSerializer f => f v
- data ToJSONOptions = ToJSONOptions {}
- defaultToJSONOptions :: ToJSONOptions
- class GToJSON v where
- gToJSON :: JSONSerializer s => ToJSONOptions -> s (v a)
- sumToEither :: (l :+: r) a -> Either (l a) (r a)
- class GToJSONObject v where
- gToJSONObject :: JSONObjectSerializer f => ToJSONOptions -> f (v a)
Documentation
class Contravariant f => Selectable f where Source #
Basically just Decidable
but without
a superclass constraint that we cannot implement for JSON.
More specifically, we can quite easily serialize some object into either a string or a number
as a top-level JSON value, but we cannot serialize both a string and a number as a top level key.
This means that we cannot implement Divisible
, but we can implement
all the operations from Decidable
.
This class lets us decide without being able to divide, which is fun to say.
giveUp :: (arg -> Void) -> f arg Source #
Give up trying to decide.
select :: (arg -> Either lhs rhs) -> f lhs -> f rhs -> f arg Source #
Pick one thing, or another, as long as you can serialize both options.
Instances
Selectable JSONBuilder Source # | |
Defined in Jordan.ToJSON.Builder giveUp :: (arg -> Void) -> JSONBuilder arg Source # select :: (arg -> Either lhs rhs) -> JSONBuilder lhs -> JSONBuilder rhs -> JSONBuilder arg Source # | |
Selectable JSONText Source # | |
class Divisible f => JSONObjectSerializer f where Source #
An abstract representation of how to serialize a JSON object.
Since serializing is the exact opposite of parsing, we have to be
Decidable
instead of Alternative
.
That is, if we are serializing a JSON object, we need to be able to break things apart.
Unfortunately the combinators for breaking things apart are more annoying to use than the combinators for putting things together, and involve a lot of tuples everywhere.
Thankfully we provide a good interface to derive these classes generically!
:: Text | Label for the field to write |
-> (forall jsonSerializer. JSONSerializer jsonSerializer => jsonSerializer a) | How to write the field.
The forall ensures that JSON serialization is kept completely abstract.
You can only use the methods of |
-> f a |
Instances
JSONObjectSerializer CommaBuilder Source # | |
Defined in Jordan.ToJSON.Text writeField :: Text -> (forall (jsonSerializer :: Type -> Type). JSONSerializer jsonSerializer => jsonSerializer a) -> CommaBuilder a Source # |
class Divisible f => JSONTupleSerializer f where Source #
:: (forall jsonSerializer. JSONSerializer jsonSerializer => jsonSerializer a) | Write a single item into the tuple. The forall keeps things abstract. |
-> f a |
Instances
JSONTupleSerializer TextArray Source # | |
Defined in Jordan.ToJSON.Text | |
JSONTupleSerializer CommaBuilder Source # | |
Defined in Jordan.ToJSON.Text writeItem :: (forall (jsonSerializer :: Type -> Type). JSONSerializer jsonSerializer => jsonSerializer a) -> CommaBuilder a Source # |
class Selectable f => JSONSerializer f where Source #
An abstract representation of how to serialize a Haskell value into JSON.
:: Text | A name for the object. Should be "globally unique" as much as possible. |
-> (forall objSerializer. JSONObjectSerializer objSerializer => objSerializer a) | How to serialize the object.
The forall here keeps things abstract: you are only allowed to use the methods of |
-> f a |
serializeDictionary :: Foldable t => (forall jsonSerializer. JSONSerializer jsonSerializer => jsonSerializer a) -> f (t (Text, a)) Source #
serializeText :: f Text Source #
serializeTextConstant :: Text -> f a Source #
Serialize some text constant. Note that this returns a serializer of anything: if you are always going to serialize out the same string, we don't need to even look at the thing we're serializing!
serializeNull :: f any Source #
serializeNumber :: f Scientific Source #
serializeBool :: f Bool Source #
serializeTuple :: (forall tupleSerializer. JSONTupleSerializer tupleSerializer => tupleSerializer a) -> f a Source #
serializeArray :: ToJSON a => f [a] Source #
Instances
A class to provide the canonical way to encode a JSON.
This class uses finally tagless style to keep the instructions for serializing abstract. This allows us to automatically generate documentation, and to generate serializers that always avoid the need for intermediate structures.
This class is derivable generically, and will generate a "nice" format. In my opinion, at least.
Nothing
toJSON :: JSONSerializer f => f v Source #
Instances
data ToJSONOptions Source #
class GToJSON v where Source #
gToJSON :: JSONSerializer s => ToJSONOptions -> s (v a) Source #
Instances
sumToEither :: (l :+: r) a -> Either (l a) (r a) Source #
class GToJSONObject v where Source #
gToJSONObject :: JSONObjectSerializer f => ToJSONOptions -> f (v a) Source #
Instances
(GToJSONObject lhs, GToJSONObject rhs) => GToJSONObject (lhs :*: rhs) Source # | |
Defined in Jordan.ToJSON.Class gToJSONObject :: JSONObjectSerializer f => ToJSONOptions -> f ((lhs :*: rhs) a) Source # | |
(GToJSON f, Selector t) => GToJSONObject (S1 t f) Source # | |
Defined in Jordan.ToJSON.Class gToJSONObject :: JSONObjectSerializer f0 => ToJSONOptions -> f0 (S1 t f a) Source # |