Skip to content

Commit 8688db1

Browse files
committed
xlsx th eliminated
1 parent f2f90f6 commit 8688db1

File tree

3 files changed

+81
-81
lines changed

3 files changed

+81
-81
lines changed

pub/xlsx/src/Codec/Xlsx/Types.hs

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{-# LANGUAGE OverloadedStrings #-}
44
{-# LANGUAGE RankNTypes #-}
55
{-# LANGUAGE RecordWildCards #-}
6-
{-# LANGUAGE TemplateHaskell #-}
76
{-# LANGUAGE NoMonomorphismRestriction #-}
87

98
module Codec.Xlsx.Types
@@ -47,13 +46,6 @@ module Codec.Xlsx.Types
4746
)
4847
where
4948

50-
import Control.Exception (SomeException, toException)
51-
#ifdef USE_MICROLENS
52-
import Lens.Micro.TH
53-
import Data.Profunctor(dimap)
54-
import Data.Profunctor.Choice
55-
#else
56-
#endif
5749
import Codec.Xlsx.Parser.Internal
5850
import Codec.Xlsx.Types.AutoFilter as X
5951
import Codec.Xlsx.Types.Cell as Cell
@@ -74,22 +66,24 @@ import Codec.Xlsx.Types.Table as X
7466
import Codec.Xlsx.Types.Variant as X
7567
import Codec.Xlsx.Writer.Internal
7668
import Control.DeepSeq (NFData)
69+
import Control.Exception (SomeException, toException)
7770
import qualified Data.ByteString.Lazy as L
7871
import Data.Default
7972
import Data.Function (on)
8073
import Data.List (groupBy)
8174
import Data.Map (Map)
8275
import qualified Data.Map as M
8376
import Data.Maybe (catMaybes, isJust)
77+
import Data.Profunctor (dimap)
78+
import Data.Profunctor.Choice
8479
import Data.Text (Text)
8580
import GHC.Generics (Generic)
8681
import Text.XML (parseLBS, renderLBS)
8782
import Text.XML.Cursor
8883
#ifdef USE_MICROLENS
8984
import Lens.Micro
9085
#else
91-
import Control.Lens (lens, Lens', makeLenses)
92-
import Control.Lens.TH (makePrisms)
86+
import Control.Lens (lens, Lens')
9387
#endif
9488

9589
-- | Height of a row in points (1/72in)
@@ -102,39 +96,38 @@ data RowHeight
10296

10397
instance NFData RowHeight
10498

105-
#ifdef USE_MICROLENS
10699
-- Since micro-lens denies the existence of prisms,
107100
-- I pasted the splice that's generated from makePrisms,
108101
-- then I copied over the definitions from Control.Lens for the prism
109102
-- function as well.
110-
type Prism s t a b = forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t)
103+
type Prism s t a b =
104+
forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t)
105+
111106
type Prism' s a = Prism s s a a
112107

113108
prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
114109
prism bt seta = dimap seta (either pure (fmap bt)) . right'
115110

116111
_CustomHeight :: Prism' RowHeight Double
117-
_CustomHeight
118-
= (prism (\ x1_a4xgd -> CustomHeight x1_a4xgd))
119-
(\ x_a4xge
120-
-> case x_a4xge of
121-
CustomHeight y1_a4xgf -> Right y1_a4xgf
122-
_ -> Left x_a4xge)
112+
_CustomHeight =
113+
(prism (\x1_a4xgd -> CustomHeight x1_a4xgd))
114+
( \x_a4xge ->
115+
case x_a4xge of
116+
CustomHeight y1_a4xgf -> Right y1_a4xgf
117+
_ -> Left x_a4xge
118+
)
123119
{-# INLINE _CustomHeight #-}
124120

125121
_AutomaticHeight :: Prism' RowHeight Double
126-
_AutomaticHeight
127-
= (prism (\ x1_a4xgg -> AutomaticHeight x1_a4xgg))
128-
(\ x_a4xgh
129-
-> case x_a4xgh of
130-
AutomaticHeight y1_a4xgi -> Right y1_a4xgi
131-
_ -> Left x_a4xgh)
122+
_AutomaticHeight =
123+
(prism (\x1_a4xgg -> AutomaticHeight x1_a4xgg))
124+
( \x_a4xgh ->
125+
case x_a4xgh of
126+
AutomaticHeight y1_a4xgi -> Right y1_a4xgi
127+
_ -> Left x_a4xgh
128+
)
132129
{-# INLINE _AutomaticHeight #-}
133130

134-
#else
135-
makePrisms ''RowHeight
136-
#endif
137-
138131
-- | Properties of a row. See 18.3.1.73 "row (Row)" for more details
139132
data RowProperties = RowProps
140133
{ -- | Row height in points

pub/xlsx/src/Codec/Xlsx/Types/Common.hs

Lines changed: 59 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
{-# LANGUAGE OverloadedStrings #-}
55
{-# LANGUAGE RankNTypes #-}
66
{-# LANGUAGE ScopedTypeVariables #-}
7-
{-# LANGUAGE TemplateHaskell #-}
87
{-# LANGUAGE TupleSections #-}
98

109
module Codec.Xlsx.Types.Common
@@ -75,6 +74,8 @@ import Data.Function ((&))
7574
import Data.Ix (inRange)
7675
import qualified Data.Map as Map
7776
import Data.Maybe (fromMaybe, isJust)
77+
import Data.Profunctor (dimap)
78+
import Data.Profunctor.Choice
7879
import Data.Text (Text)
7980
import qualified Data.Text as T
8081
import qualified Data.Text.Encoding as T
@@ -88,8 +89,6 @@ import Text.XML.Cursor
8889
import Lens.Micro
8990
import Lens.Micro.Internal
9091
import Lens.Micro.GHC ()
91-
import Data.Profunctor.Choice
92-
import Data.Profunctor(dimap)
9392
#else
9493
import Control.Lens(makePrisms)
9594
#endif
@@ -670,77 +669,85 @@ instance ToAttrVal ErrorType where
670669
toAttrVal ErrorRef = "#REF!"
671670
toAttrVal ErrorValue = "#VALUE!"
672671

673-
#ifdef USE_MICROLENS
674672
-- Since micro-lens denies the existence of prisms,
675673
-- I pasted the splice that's generated from makePrisms,
676674
-- then I copied over the definitions from Control.Lens for the prism
677675
-- function as well.
678676
-- Essentially this is doing the template haskell by hand.
679-
type Prism s t a b = forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t)
677+
type Prism s t a b =
678+
forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t)
679+
680680
type Prism' s a = Prism s s a a
681681

682682
prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
683683
prism bt seta = dimap seta (either pure (fmap bt)) . right'
684684

685685
_CellText :: Prism' CellValue Text
686-
_CellText
687-
= (prism (\ x1_a1ZQv -> CellText x1_a1ZQv))
688-
(\ x_a1ZQw
689-
-> case x_a1ZQw of
690-
CellText y1_a1ZQx -> Right y1_a1ZQx
691-
_ -> Left x_a1ZQw)
686+
_CellText =
687+
(prism (\x1_a1ZQv -> CellText x1_a1ZQv))
688+
( \x_a1ZQw ->
689+
case x_a1ZQw of
690+
CellText y1_a1ZQx -> Right y1_a1ZQx
691+
_ -> Left x_a1ZQw
692+
)
692693
{-# INLINE _CellText #-}
694+
693695
_CellDouble :: Prism' CellValue Double
694-
_CellDouble
695-
= (prism (\ x1_a1ZQy -> CellDouble x1_a1ZQy))
696-
(\ x_a1ZQz
697-
-> case x_a1ZQz of
698-
CellDouble y1_a1ZQA -> Right y1_a1ZQA
699-
_ -> Left x_a1ZQz)
696+
_CellDouble =
697+
(prism (\x1_a1ZQy -> CellDouble x1_a1ZQy))
698+
( \x_a1ZQz ->
699+
case x_a1ZQz of
700+
CellDouble y1_a1ZQA -> Right y1_a1ZQA
701+
_ -> Left x_a1ZQz
702+
)
700703
{-# INLINE _CellDouble #-}
704+
701705
_CellBool :: Prism' CellValue Bool
702-
_CellBool
703-
= (prism (\ x1_a1ZQB -> CellBool x1_a1ZQB))
704-
(\ x_a1ZQC
705-
-> case x_a1ZQC of
706-
CellBool y1_a1ZQD -> Right y1_a1ZQD
707-
_ -> Left x_a1ZQC)
706+
_CellBool =
707+
(prism (\x1_a1ZQB -> CellBool x1_a1ZQB))
708+
( \x_a1ZQC ->
709+
case x_a1ZQC of
710+
CellBool y1_a1ZQD -> Right y1_a1ZQD
711+
_ -> Left x_a1ZQC
712+
)
708713
{-# INLINE _CellBool #-}
714+
709715
_CellRich :: Prism' CellValue [RichTextRun]
710-
_CellRich
711-
= (prism (\ x1_a1ZQE -> CellRich x1_a1ZQE))
712-
(\ x_a1ZQF
713-
-> case x_a1ZQF of
714-
CellRich y1_a1ZQG -> Right y1_a1ZQG
715-
_ -> Left x_a1ZQF)
716+
_CellRich =
717+
(prism (\x1_a1ZQE -> CellRich x1_a1ZQE))
718+
( \x_a1ZQF ->
719+
case x_a1ZQF of
720+
CellRich y1_a1ZQG -> Right y1_a1ZQG
721+
_ -> Left x_a1ZQF
722+
)
716723
{-# INLINE _CellRich #-}
724+
717725
_CellError :: Prism' CellValue ErrorType
718-
_CellError
719-
= (prism (\ x1_a1ZQH -> CellError x1_a1ZQH))
720-
(\ x_a1ZQI
721-
-> case x_a1ZQI of
722-
CellError y1_a1ZQJ -> Right y1_a1ZQJ
723-
_ -> Left x_a1ZQI)
726+
_CellError =
727+
(prism (\x1_a1ZQH -> CellError x1_a1ZQH))
728+
( \x_a1ZQI ->
729+
case x_a1ZQI of
730+
CellError y1_a1ZQJ -> Right y1_a1ZQJ
731+
_ -> Left x_a1ZQI
732+
)
724733
{-# INLINE _CellError #-}
725734

726735
_XlsxText :: Prism' XlsxText Text
727-
_XlsxText
728-
= (prism (\ x1_a1ZzU -> XlsxText x1_a1ZzU))
729-
(\ x_a1ZzV
730-
-> case x_a1ZzV of
731-
XlsxText y1_a1ZzW -> Right y1_a1ZzW
732-
_ -> Left x_a1ZzV)
736+
_XlsxText =
737+
(prism (\x1_a1ZzU -> XlsxText x1_a1ZzU))
738+
( \x_a1ZzV ->
739+
case x_a1ZzV of
740+
XlsxText y1_a1ZzW -> Right y1_a1ZzW
741+
_ -> Left x_a1ZzV
742+
)
733743
{-# INLINE _XlsxText #-}
744+
734745
_XlsxRichText :: Prism' XlsxText [RichTextRun]
735-
_XlsxRichText
736-
= (prism (\ x1_a1ZzX -> XlsxRichText x1_a1ZzX))
737-
(\ x_a1ZzY
738-
-> case x_a1ZzY of
739-
XlsxRichText y1_a1ZzZ -> Right y1_a1ZzZ
740-
_ -> Left x_a1ZzY)
746+
_XlsxRichText =
747+
(prism (\x1_a1ZzX -> XlsxRichText x1_a1ZzX))
748+
( \x_a1ZzY ->
749+
case x_a1ZzY of
750+
XlsxRichText y1_a1ZzZ -> Right y1_a1ZzZ
751+
_ -> Left x_a1ZzY
752+
)
741753
{-# INLINE _XlsxRichText #-}
742-
743-
#else
744-
makePrisms ''XlsxText
745-
makePrisms ''CellValue
746-
#endif

pub/xlsx/xlsx.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ common pkg
6969
, mtl >=2.1
7070
, network-uri
7171
, old-locale >=1.0.0.5
72+
, profunctors
7273
, safe >=0.3
7374
, text >=0.11.3.1
7475
, time >=1.4.0.1
@@ -91,7 +92,6 @@ common pkg
9192
, microlens-mtl
9293
, microlens-platform
9394
, microlens-th
94-
, profunctors
9595

9696
cpp-options: -DUSE_MICROLENS
9797

0 commit comments

Comments
 (0)