1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Prolog
(
-- * Modules
module Control.Applicative
, module Control.Monad
, module Control.Monad.Except
, module Control.Monad.Identity
, module Control.Monad.IO.Class
, module Control.Monad.Reader
, module Data.Bifunctor
, module Data.Bifoldable
, module Data.Bitraversable
, module Data.Bool
, module Data.Either
, module Data.Foldable
, module Data.Function
, module Data.Functor
, module Data.Functor.Contravariant
, module Data.Maybe
-- * Types
, Binary
, Generic
, Generically (..)
, MonadThrow (..)
, Exception (..)
, SomeException (..)
, B.StrictByteString
, BL.LazyByteString
, T.StrictText
, TL.LazyText
-- * Strings
, IsString (..)
, StringConv (..)
, toS
, toSL
, convS
, convSL
, renderTo
, fromStringlike
-- * Utils
, (<<$>>)
, (<<<$>>>)
, (<<&>>)
, (-->)
, (-/>)
, (>>=?)
, foreach
, liftMaybe
, squashMaybe
) where
import Control.Applicative
import Control.Comonad
import Control.Monad
import Control.Monad.Catch
import Control.Monad.Except
import Control.Monad.Identity
import Control.Monad.IO.Class
import Control.Monad.Reader
import Data.Bifunctor
import Data.Bifoldable
import Data.Binary
import Data.Bitraversable
import Data.Bool
import Data.ByteString qualified as B
import Data.ByteString.Lazy qualified as BL
import Data.Either
import Data.Foldable
import Data.Function
import Data.Functor
import Data.Functor.Contravariant
import Data.Maybe
import Data.String
import Data.String.Conv
import Data.Text qualified as T
import Data.Text.Lazy qualified as TL
import GHC.Generics
import Hakyll qualified as H
import Text.Blaze.Html
import Text.Blaze.Html.Renderer.Pretty as BS
import Text.Blaze.Html.Renderer.Text as BT
import Text.Blaze.Html.Renderer.Utf8 as BB
import Text.LaTeX.Base qualified as L
(<<$>>) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b)
infixl 4 <<$>>
(<<$>>) = fmap fmap fmap
{-# INLINE (<<$>>) #-}
(<<<$>>>) :: (Functor f, Functor g, Functor h) => (a -> b) -> f (g (h a)) -> f (g (h b))
infixl 4 <<<$>>>
(<<<$>>>) = fmap . fmap . fmap
{-# INLINE (<<<$>>>) #-}
(<<&>>) :: (Functor f, Functor g) => f (g a) -> (a -> b) -> f (g b)
infixl 1 <<&>>
(<<&>>) = flip (<<$>>)
{-# INLINE (<<&>>) #-}
foreach :: Functor f => f a -> (a -> b) -> f b
foreach = flip fmap
{-# INLINE foreach #-}
(-->) :: (Monad m, Monoid w) => m Bool -> m w -> m w
infixr 0 -->
b --> a = b >>= bool (pure mempty) a
{-# INLINE (-->) #-}
(-/>) :: (Monad m, Monoid w) => m Bool -> m w -> m w
infixr 0 -/>
(-/>) = (-->) . fmap not
{-# INLINE (-/>) #-}
(>>=?) :: (Monad m, Monoid w) => m (Maybe a) -> (a -> m w) -> m w
infixl 1 >>=?
x >>=? f = x >>= maybe (pure mempty) f
{-# INLINE (>>=?) #-}
liftMaybe :: Alternative m => Maybe a -> m a
liftMaybe = maybe empty pure
{-# INLINE liftMaybe #-}
squashMaybe :: Alternative m => m (Maybe a) -> m a
squashmaybe = (>>= liftMaybe)
{-# INLINE squashMaybe #-}
renderTo :: (StringConv T.Text s, L.Render r) => r -> s
renderTo = toSL . L.render
{-# INLINE renderTo #-}
fromStringlike :: (IsString s, StringConv t String) => t -> s
fromStringlike = fromString . toSL
{-# INLINE fromStringlike #-}
-- Orphan instances
instance Binary L.MathType
instance Binary L.Measure
instance Binary L.TeXArg
instance Binary L.LaTeX
instance H.Writable L.LaTeX where
write p = L.renderFile p . H.itemBody
instance Contravariant H.Context where
contramap f (H.Context c) = H.Context $ \x xs -> c x xs . fmap f
instance Comonad H.Item where
extract = H.itemBody
duplicate = join (<$)
instance StringConv L.LaTeX T.Text where
strConv _ = L.render
instance StringConv L.LaTeX TL.Text where
strConv l = strConv l . L.render
instance StringConv L.LaTeX B.ByteString where
strConv l = strConv l . L.render
instance StringConv L.LaTeX BL.ByteString where
strConv l = strConv l . L.render
instance StringConv L.LaTeX String where
strConv l = strConv l . L.render
instance StringConv Html T.Text where
strConv _ = BT.renderHtml
instance StringConv Html TL.Text where
strConv l = strConv l . BT.renderHtml
instance StringConv Html String where
strConv _ = BS.renderHtml
instance StringConv Html B.ByteString where
strConv l = strConv l . BB.renderHtml
instance StringConv Html BL.ByteString where
strConv _ = BB.renderHtml
|