From 7a83952badf91998afc10f3b4c2e9b47f663bf11 Mon Sep 17 00:00:00 2001 From: Alp Mestanogullari Date: Wed, 11 Mar 2015 11:46:35 +0100 Subject: [PATCH] some more documentation, code cleanup + changelog entry --- CHANGELOG.md | 1 + src/Servant/API.hs | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 741ff87e..a3194b03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ 0.3 --- +* Add a `Canonicalize` type family that distributes all `:>`s inside `:<|>`s to get to the canonical type of an API -- which is then used in all other packages to avoid weird handler types in *servant-server*. * Multiple content-type/accept support for all the relevant combinators * Provide *JSON*, *PlainText*, *OctetStream* and *FormUrlEncoded* content types out of the box * Type-safe link generation to API endpoints diff --git a/src/Servant/API.hs b/src/Servant/API.hs index 42ace00e..9a91d0f4 100644 --- a/src/Servant/API.hs +++ b/src/Servant/API.hs @@ -80,7 +80,12 @@ import Servant.Utils.Links (HasLink (..), IsElem, IsElem', -- | Turn an API type into its canonical form. -- --- The canonical form is defined and will basically turn: +-- The canonical form of an API type is basically the all-flattened form +-- of the original type. More formally, it takes a type as input and hands you +-- back an /equivalent/ type formed of toplevel `:<|>`-separated chains of `:>`s, +-- i.e with all `:>`s distributed inside the `:<|>`s. +-- +-- It basically turns: -- -- > "hello" :> (Get Hello :<|> ReqBody Hello :> Put Hello) -- @@ -101,5 +106,5 @@ type family Redex a b c :: * where Redex a a first = Canonicalize first :> a Redex a b first = Canonicalize (first :> b) -canonicalize :: Canonicalize layout ~ t => Proxy layout -> Proxy t +canonicalize :: Proxy layout -> Proxy (Canonicalize layout) canonicalize Proxy = Proxy