-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Specify Servant APIs with records.
--   
--   Specify Servant APIs with records instead of <tt>:&lt;|&gt;</tt>
--   trees. See the <a>README</a> for more information. <b>This package has
--   been merged into servant 0.14.1, please use that instead if
--   available.</b>
@package servant-generic
@version 0.1.0.3

module Servant.Generic

-- | A type family that applies an appropriate type family to the
--   <tt>api</tt> parameter. For example, passing <a>AsApi</a> will leave
--   <tt>api</tt> untouched, while <tt><a>AsServerT</a> m</tt> will produce
--   <tt><a>ServerT</a> api m</tt>.

-- | A type that specifies that an API record contains a server
--   implementation.
data AsServerT (m :: * -> *)
type AsServer = AsServerT Handler

-- | A type that specifies that an API record contains an API definition.
--   Only useful at type-level.
data AsApi

-- | A type that specifies that an API record contains a set of links.
--   
--   (Useful since servant 0.12)
data AsLink

-- | Turns a generic product type into a linear tree of <a>:&lt;|&gt;</a>
--   combinators. For example, given
--   
--   <pre>
--   data Foo route = Foo
--     { foo :: route :-
--         Get '[PlainText] Text
--     , bar :: route :-
--         Get '[PlainText] Text
--     }
--   </pre>
--   
--   <pre>
--   ToServant (Foo AsApi) ~ Get '[PlainText] Text :&lt;|&gt; Get '[PlainText] Text
--   </pre>
type ToServant a = GToServant (Rep a)

-- | See <a>ToServant</a>, but at value-level.
toServant :: GenericProduct a => a -> ToServant a

-- | Inverse of <a>toServant</a>.
--   
--   This can be used to turn <tt>generated</tt> values such as client
--   functions into records.
--   
--   You may need to provide a type signature for the <i>output</i> type
--   (your record type).
fromServant :: GenericProduct a => ToServant a -> a
type GenericProduct a = (Generic a, GProduct (Rep a))

-- | A class of generic product types.
class GProduct f where {
    type family GToServant f;
}
gtoServant :: GProduct f => f p -> GToServant f
gfromServant :: GProduct f => GToServant f -> f p

-- | Representable types of kind *. This class is derivable in GHC with the
--   DeriveGeneric flag on.
class Generic a where {
    type family Rep a :: * -> *;
}

-- | Convert from the datatype to its representation
from :: Generic a => a -> Rep a x

-- | Convert from the representation to the datatype
to :: Generic a => Rep a x -> a

-- | Given an API record field, create a link for that route. Only the
--   field's type is used.
fieldLink :: forall routes endpoint. (IsElem endpoint (ToServant (routes AsApi)), HasLink endpoint) => (routes AsApi -> endpoint) -> MkLink endpoint
instance Servant.Generic.GProduct f => Servant.Generic.GProduct (GHC.Generics.M1 i c f)
instance (Servant.Generic.GProduct l, Servant.Generic.GProduct r) => Servant.Generic.GProduct (l GHC.Generics.:*: r)
instance Servant.Generic.GProduct (GHC.Generics.K1 i c)
