Upd: Nillable cenvenience stuff

This commit is contained in:
Aleksey Uimanov 2020-03-06 12:25:34 +05:00
parent b35a07a445
commit 380bdea956
6 changed files with 39 additions and 11 deletions

View File

@ -1,3 +1,7 @@
nix:
packages:
- zlib
resolver: lts-9.21
packages:

View File

@ -1 +1,5 @@
nix:
packages:
- zlib
resolver: lts-11.22

View File

@ -1,3 +1,7 @@
nix:
packages:
- zlib
resolver: lts-12.16
extra-deps:
- dom-parser-3.1.0

View File

@ -1,23 +1,33 @@
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Text.XML.Nillable
where
module Text.XML.Nillable where
import Control.DeepSeq
import Text.XML.DOM.Parser
import Text.XML.Writer
import Text.XML.ParentAttributes
import Control.DeepSeq
import Control.Lens
import Text.XML.DOM.Parser
import Text.XML.ParentAttributes
import Text.XML.Writer
-- | Type that can have explicit null value
--
-- Null value is indicated by "nil"="true" attribute.
newtype Nillable a = Nillable (Maybe a)
deriving (Eq, Show, Ord, Read, NFData, ToXML)
deriving
( Eq, Show, Ord, Read, NFData, ToXML
, Functor, Applicative, Monad, Foldable, Traversable)
_Nillable :: Prism' (Nillable a) a
_Nillable = coerced . _Just
nNill :: Nillable a
nNill = Nillable Nothing
nJust :: a -> Nillable a
nJust = Nillable . Just
instance ToXmlParentAttributes a => ToXmlParentAttributes (Nillable a) where
toXmlParentAttributes (Nillable Nothing) =
toXmlParentAttributes (Nillable Nothing) =
[("{http://www.w3.org/2001/XMLSchema-instance}nil", "true")]
toXmlParentAttributes (Nillable (Just a)) = toXmlParentAttributes a
@ -28,4 +38,4 @@ instance FromDom a => FromDom (Nillable a) where
Right
case nil of
Just "true" -> return (Nillable Nothing)
_ -> Nillable . Just <$> fromDom
_ -> Nillable . Just <$> fromDom

View File

@ -1,3 +1,7 @@
nix:
packages:
- zlib
resolver: lts-10.0
extra-deps:
- dom-parser-3.0.0

View File

@ -53,7 +53,9 @@ library
default-language: Haskell2010
default-extensions: CPP
, DeriveTraversable
, FlexibleInstances
, GeneralizedNewtypeDeriving
, LambdaCase
, TemplateHaskell
, TupleSections