Copyright | (c) Abhinav Gupta 2015 |
---|---|
License | BSD3 |
Maintainer | Abhinav Gupta <mail@abhinavg.net> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Pinch.Internal.Generic
Description
Implements support for automatically deriving Pinchable instances for types
that implement Generic
and follow a specific pattern.
Documentation
Fields of data types that represent structs, unions, and exceptions
should be wrapped inside Field
and tagged with the field identifier.
data Foo = Foo (Field 1 Text) (Field 2 (Maybe Int32)) deriving Generic instance Pinchable Foo
data A = A (Field 1 Int32) | B (Field 2 Text) deriving Generic instance Pinchable Foo
Fields which hold Maybe
values are treated as optional. All fields values
must be Pinchable
to automatically derive a Pinchable
instance for the
new data type.
Constructors
Field a |
Instances
Functor (Field n) | |
Foldable (Field n) | |
Traversable (Field n) | |
Bounded a => Bounded (Field n a) | |
Enum a => Enum (Field n a) | |
Eq a => Eq (Field n a) | |
Ord a => Ord (Field n a) | |
Show a => Show (Field n a) | |
Generic (Field n a) | |
Monoid a => Monoid (Field n a) | |
NFData a => NFData (Field n a) | |
(Pinchable a, KnownNat n) => GPinchable (K1 i (Field n (Maybe a))) | |
(Pinchable a, KnownNat n) => GPinchable (K1 i (Field n a)) | |
type Rep (Field n a) | |
type GTag (K1 i (Field n (Maybe a))) = TStruct | |
type GTag (K1 i (Field n a)) = TStruct |
getField :: Field n a -> a Source
Gets the current value of a field.
let Foo a' _ = {- ... -} a = getField a'
putField :: a -> Field n a Source
Puts a value inside a field.
Foo (putField "Hello") (putField (Just 42))
field :: Functor f => (a -> f b) -> Field n a -> f (Field n b) Source
A lens on Field
wrappers for use with the lens library.
person & name . field .~ "new value"
data Enumeration n Source
Data types that represent Thrift enums must have one constructor for each
enum item accepting an Enumeration
object tagged with the corresponding
enum value.
data Role = RoleUser (Enumeration 1) | RoleAdmin (Enumeration 2) deriving Generic instance Pinchable Role
Constructors
Enumeration |
Instances
Eq (Enumeration n) | |
Ord (Enumeration n) | |
Show (Enumeration n) | |
Generic (Enumeration n) | |
NFData (Enumeration n) | |
KnownNat n => GPinchable (K1 i (Enumeration n)) | |
type Rep (Enumeration n) | |
type GTag (K1 i (Enumeration n)) = TEnum |
enum :: Enumeration n Source
Convenience function to construct Enumeration
objects.
let role = RoleUser enum
Represents a void
result for methods.
This should be used as an element in a response union along with Field
tags.
For a method,
void setValue(..) throws (1: ValueAlreadyExists alreadyExists, 2: InternalError internalError)
Something similar to the following can be used.
data SetValueResponse = SetValueAlreadyExists (Field 1 ValueAlreadyExists) | SetValueInternalError (Field 2 InternalError) | SetValueSuccess Void deriving (Generic) instance Pinchable SetValueResponse
Constructors
Void |