Skip to content

Commit f80fe80

Browse files
phadejFacebook Github Bot
authored and
Facebook Github Bot
committed
Make haxl compile cleanly with stack build --pedantic
Summary: Closes #56 Reviewed By: JonCoens Differential Revision: D3973977 Pulled By: simonmar fbshipit-source-id: 527e17407dbeb3376955733949b0edb8b581122a
1 parent f5ecbea commit f80fe80

File tree

8 files changed

+40
-14
lines changed

8 files changed

+40
-14
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
cabal.sandbox.config
33
dist
44
*~
5+
.stack-work/
6+
dist-newstyle/

Haxl/Core/Exception.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ import GHC.Stack
100100
-- (generic transient failure) or 'CriticalError' (internal failure).
101101
--
102102
data HaxlException
103-
= forall e. (Exception e, MiddleException e)
103+
= forall e. (MiddleException e)
104104
=> HaxlException
105105
(Maybe Stack) -- filled in with the call stack when thrown,
106106
-- if PROFILING is on
@@ -129,11 +129,11 @@ instance ToJSON HaxlException where
129129
]
130130

131131
haxlExceptionToException
132-
:: (Exception e, MiddleException e) => e -> SomeException
132+
:: (MiddleException e) => e -> SomeException
133133
haxlExceptionToException = toException . HaxlException Nothing
134134

135135
haxlExceptionFromException
136-
:: (Exception e, MiddleException e) => SomeException -> Maybe e
136+
:: (MiddleException e) => SomeException -> Maybe e
137137
haxlExceptionFromException x = do
138138
HaxlException _ a <- fromException x
139139
cast a

Haxl/Core/Monad.hs

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
{-# LANGUAGE RankNTypes #-}
2020
{-# LANGUAGE ScopedTypeVariables #-}
2121
{-# LANGUAGE TypeFamilies #-}
22+
#if __GLASGOW_HASKELL >= 800
23+
{-# OPTIONS_GHC -Wno-name-shadowing #-}
24+
#else
25+
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
26+
#endif
2227

2328
-- | The implementation of the 'Haxl' monad. Most users should
2429
-- import "Haxl.Core" instead of importing this module directly.

Haxl/Core/Types.hs

+16-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
{-# LANGUAGE RecordWildCards #-}
1717
{-# LANGUAGE ScopedTypeVariables #-}
1818
{-# LANGUAGE TypeFamilies #-}
19+
#if __GLASGOW_HASKELL >= 800
20+
{-# OPTIONS_GHC -Wno-name-shadowing #-}
21+
#else
22+
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
23+
#endif
1924

2025
-- | Base types used by all of Haxl. Most users should import
2126
-- "Haxl.Core" instead of importing this module directly.
@@ -135,17 +140,25 @@ defaultFlags = Flags
135140
, caching = 1
136141
}
137142

143+
#if __GLASGOW_HASKELL__ >= 710
144+
#define FUNMONAD Monad m
145+
#else
146+
#define FUNMONAD (Functor m, Monad m)
147+
#endif
148+
138149
-- | Runs an action if the tracing level is above the given threshold.
139-
ifTrace :: (Functor m, Monad m) => Flags -> Int -> m a -> m ()
150+
ifTrace :: FUNMONAD => Flags -> Int -> m a -> m ()
140151
ifTrace flags i = when (trace flags >= i) . void
141152

142153
-- | Runs an action if the report level is above the given threshold.
143-
ifReport :: (Functor m, Monad m) => Flags -> Int -> m a -> m ()
154+
ifReport :: FUNMONAD => Flags -> Int -> m a -> m ()
144155
ifReport flags i = when (report flags >= i) . void
145156

146-
ifProfiling :: (Functor m, Monad m) => Flags -> m a -> m ()
157+
ifProfiling :: FUNMONAD => Flags -> m a -> m ()
147158
ifProfiling flags = when (report flags >= 4) . void
148159

160+
#undef FUNMONAD
161+
149162
-- ---------------------------------------------------------------------------
150163
-- Stats
151164

Haxl/Prelude.hs

+5-4
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,11 @@ sequence_ :: (Traversable t, Applicative f) => t (f a) -> f ()
189189
sequence_ t = void $ sequenceA t
190190

191191
-- | See 'mapM'.
192-
filterM :: (Applicative f, Monad f) => (a -> f Bool) -> [a] -> f [a]
193-
filterM pred xs = do
194-
bools <- mapM pred xs
195-
return [ x | (x,True) <- zip xs bools ]
192+
filterM :: (Applicative f) => (a -> f Bool) -> [a] -> f [a]
193+
filterM predicate xs =
194+
filt <$> mapM predicate xs
195+
where
196+
filt bools = [ x | (x,True) <- zip xs bools ]
196197

197198
--------------------------------------------------------------------------------
198199

haxl.cabal

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ library
8080

8181
ghc-options:
8282
-Wall
83-
-fno-warn-name-shadowing
8483

8584

8685
test-suite test

tests/ExampleDataSource.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,4 @@ countAardvarks :: String -> GenHaxl () Int
154154
countAardvarks str = dataFetch (CountAardvarks str)
155155

156156
listWombats :: Id -> GenHaxl () [Id]
157-
listWombats id = dataFetch (ListWombats id)
157+
listWombats i = dataFetch (ListWombats i)

tests/MonadBench.hs

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
-- be found in the PATENTS file.
77

88
-- | Benchmarking tool for core performance characteristics of the Haxl monad.
9-
9+
{-# LANGUAGE CPP #-}
10+
#if __GLASGOW_HASKELL >= 800
11+
{-# OPTIONS_GHC -Wno-name-shadowing #-}
12+
#else
13+
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
14+
#endif
1015
module MonadBench (main) where
1116

1217
import Control.Monad
@@ -32,6 +37,7 @@ testEnv = do
3237
let st = stateSet exstate stateEmpty
3338
initEnv st ()
3439

40+
main :: IO ()
3541
main = do
3642
[test,n_] <- getArgs
3743
let n = read n_
@@ -49,7 +55,7 @@ main = do
4955
foldr andThen (return ()) (replicate n (listWombats 3))
5056
-- sequential, left-associated, distinct queries
5157
"seql" -> runHaxl env $ do
52-
foldl andThen (return []) (map listWombats [1.. fromIntegral n])
58+
_ <- foldl andThen (return []) (map listWombats [1.. fromIntegral n])
5359
return ()
5460
"tree" -> runHaxl env $ void $ tree n
5561
-- No memoization

0 commit comments

Comments
 (0)