[0.1.0.3] no overlapping instances, mimeUnrenderXML

parent 2561631f
# Revision history for servant-xml-conduit
## [0.1.0.3] - 2023-11-23
### Fixed
- documentation generation (add `cabal.project` with `allow-newer` for `base`)
- fix overlapping instances
## [0.1.0.2] - 2023-11-23
### Added
- `.cabal`: added homepage, bug-reports, source-repository
## [0.1.0.1] - 2023-11 23
### Fixed
......
with-compiler: ghc-8.10.7
allow-newer: base
packages:
./
......@@ -20,14 +20,14 @@ name: servant-xml-conduit
-- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change
version: 0.1.0.1
version: 0.1.0.3
-- A short (one-line) description of the package.
synopsis: Servant XML content-type with support for xml-conduit
-- A longer description of the package.
description: This is similar in spirit to `servant-xml` but uses `xml-conduit` instead of `xmlbf`.
-- The license under which the package is released.
license: AGPL-3.0-or-later
......@@ -40,6 +40,9 @@ author: Gargantext
-- An email address to which users can send suggestions, bug reports, and patches.
maintainer: pk@intrepidus.pl
homepage: https://gitlab.iscpif.fr/gargantext/servant-xml-conduit
bug-reports: https://gitlab.iscpif.fr/gargantext/servant-xml-conduit/issues
-- A copyright notice.
-- copyright:
category: Web
......@@ -51,6 +54,10 @@ extra-doc-files: CHANGELOG.md
-- Extra source files to be distributed with the package, such as examples, or a tutorial module.
-- extra-source-files:
source-repository head
type: git
location: https://gitlab.iscpif.fr/gargantext/servant-xml-conduit
common warnings
ghc-options: -Wall
......
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-|
Module : Servant.XML.Conduit
Description : Servant bindings for XML using xml-conduit
......@@ -14,6 +11,7 @@ Portability : POSIX
module Servant.XML.Conduit where
import Data.Bifunctor (first)
import Data.ByteString.Lazy qualified as BSL
import Network.HTTP.Media qualified as M
import Servant.API
import Text.XML qualified as XML
......@@ -24,7 +22,42 @@ data XML
instance Accept XML where
contentType _ = "application" M.// "xml" M./: ("charset", "utf-8")
instance {-# OVERLAPPING #-} MimeUnrender XML XML.Document where
mimeUnrender _ bs = first show $ XML.parseLBS XML.def bs
instance MimeRender XML XML.Document where
mimeRender _ doc = XML.renderLBS XML.def doc
{-| Function to decode a lazy `ByteString' into 'XML.Document'. The
reason we don't privde a @'MimeUnrender' 'XML' 'XML.Document'@ instance is
that we don't want to force users with a predefined 'FromXML'
typeclass.
If we added
@
instance 'MimeUnrender' 'XML' 'XML.Document' where
mimeUnrender _ bs = first show $ 'XML.parseLBS' 'XML.def' bs
@
we immediately arrive at overlapping instances problem when we try to define
@
instance FromXML a => 'MimeUnrender' 'XML' a ...
@
So, just define this in your code:
@
data ParseError =
ErrorNoElementFound Text
| ...
class FromXML a where
fromXML :: (Functor m, Applicative m, MonadError ParseError m) => 'Text.XML.Cursor.Cursor' -> m a
instance (FromXML a) => 'MimeUnrender' 'XML' a where
mimeUnrender _ctype bs = case 'mimeUnrenderXML' bs of
Left err -> Left err
Right doc -> first show $ fromXML ('Text.XML.Cursor.fromDocument' doc)
@
-}
mimeUnrenderXML :: BSL.ByteString -> Either String XML.Document
mimeUnrenderXML bs = first show $ XML.parseLBS XML.def bs
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment