git.iko.soy/typeable/xml-isogen
on master help sign in
Merge pull request #28 from typeable/nillable-stuff

Upd: Nillable cenvenience stuff

commit288ad860fda19c53f32788aaa76ff8f51b2c3362 authorAlexey Uimanov <s9gf4ult@gmail.com> dateFri 6 Mar 2020, 12:55 (7 years ago) parentb35a07a0cb0fa4
7 files changed+44−12
ghc-802.yaml+4 ghc-822.yaml+4 ghc-844.yaml+4 src/Data/THGen/Orphans.hs+3−1 src/Text/XML/Nillable.hs+21−11 stack.yaml+4 xml-isogen.cabal+4
ghc-802.yaml+4
@@ -1,3 +1,7 @@
1+nix:
2+ packages:
3+ - zlib
4+
15resolver: lts-9.21
26
37packages:
ghc-822.yaml+4
@@ -1 +1,5 @@
1+nix:
2+ packages:
3+ - zlib
4+
15resolver: lts-11.22
ghc-844.yaml+4
@@ -1,3 +1,7 @@
1+nix:
2+ packages:
3+ - zlib
4+
15resolver: lts-12.16
26extra-deps:
37- dom-parser-3.1.0
src/Data/THGen/Orphans.hs+3−1
@@ -1,8 +1,10 @@
1+{-# OPTIONS_GHC -fno-warn-orphans #-}
2+
13module Data.THGen.Orphans
24where
35
4−import qualified Data.Text as Text
56import Data.Scientific
7+import qualified Data.Text as Text
68import Text.XML.Writer
79
810instance ToXML Scientific where
src/Text/XML/Nillable.hs+21−11
@@ -1,23 +1,33 @@
1+{-# LANGUAGE MonoLocalBinds #-}
12{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE MonoLocalBinds #-}
3−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
43
5−module Text.XML.Nillable
6−where
4+module Text.XML.Nillable where
75
8−import Control.DeepSeq
9−import Text.XML.DOM.Parser
10−import Text.XML.Writer
11−import Text.XML.ParentAttributes
6+import Control.DeepSeq
7+import Control.Lens
8+import Text.XML.DOM.Parser
9+import Text.XML.ParentAttributes
10+import Text.XML.Writer
1211
1312-- | Type that can have explicit null value
1413--
1514-- Null value is indicated by "nil"="true" attribute.
1615newtype Nillable a = Nillable (Maybe a)
17− deriving (Eq, Show, Ord, Read, NFData, ToXML)
16+ deriving
17+ ( Eq, Show, Ord, Read, NFData, ToXML
18+ , Functor, Applicative, Monad, Foldable, Traversable)
19+
20+_Nillable :: Prism' (Nillable a) a
21+_Nillable = coerced . _Just
22+
23+nNill :: Nillable a
24+nNill = Nillable Nothing
25+
26+nJust :: a -> Nillable a
27+nJust = Nillable . Just
1828
1929instance ToXmlParentAttributes a => ToXmlParentAttributes (Nillable a) where
20− toXmlParentAttributes (Nillable Nothing) =
30+ toXmlParentAttributes (Nillable Nothing) =
2131 [("{http://www.w3.org/2001/XMLSchema-instance}nil", "true")]
2232 toXmlParentAttributes (Nillable (Just a)) = toXmlParentAttributes a
2333
@@ -28,4 +38,4 @@ instance FromDom a => FromDom (Nillable a) where
2838 Right
2939 case nil of
3040 Just "true" -> return (Nillable Nothing)
31− _ -> Nillable . Just <$> fromDom
41+ _ -> Nillable . Just <$> fromDom
stack.yaml+4
@@ -1,3 +1,7 @@
1+nix:
2+ packages:
3+ - zlib
4+
15resolver: lts-10.0
26extra-deps:
37- dom-parser-3.0.0
xml-isogen.cabal+4
@@ -49,11 +49,15 @@ library
4949 , xml-conduit-writer >= 0.1
5050 , scientific
5151
52+ ghc-options: -Wall
53+
5254 hs-source-dirs: src
5355
5456 default-language: Haskell2010
5557 default-extensions: CPP
58+ , DeriveTraversable
5659 , FlexibleInstances
60+ , GeneralizedNewtypeDeriving
5761 , LambdaCase
5862 , TemplateHaskell
5963 , TupleSections