git.iko.soy/distributed-process
on master help sign in
Reduce number of required language exts
1569533Edsko de Vries
network-transport-2/network-transport.cabal+7−7
@@ -19,7 +19,7 @@ Library
19 Network.Transport.Chan,
19 Network.Transport.Chan,
20 Network.Transport.TCP,
20 Network.Transport.TCP,
21 Network.Transport.Util
21 Network.Transport.Util
22− extensions: EmptyDataDecls, OverloadedStrings, ForeignFunctionInterface, FlexibleContexts, BangPatterns, ScopedTypeVariables, DeriveDataTypeable
22+ extensions: OverloadedStrings, ForeignFunctionInterface, DeriveDataTypeable
23 ghc-options: -Wall -fno-warn-unused-do-bind
23 ghc-options: -Wall -fno-warn-unused-do-bind
24 HS-Source-Dirs: src
24 HS-Source-Dirs: src
25
25
@@ -27,14 +27,14 @@ Test-Suite TestTCP
27 Type: exitcode-stdio-1.0
27 Type: exitcode-stdio-1.0
28 Main-Is: TestTCP.hs
28 Main-Is: TestTCP.hs
29 Build-Depends: base,
29 Build-Depends: base,
30− containers,
31 bytestring,
30 bytestring,
31+ containers,
32 data-accessor,
32 data-accessor,
33 network,
33 network,
34 mtl,
34 mtl,
35 transformers,
35 transformers,
36 ansi-terminal
36 ansi-terminal
37− extensions: EmptyDataDecls, OverloadedStrings, ForeignFunctionInterface, FlexibleContexts, BangPatterns, ScopedTypeVariables, DeriveDataTypeable
37+ extensions: OverloadedStrings, ForeignFunctionInterface, FlexibleContexts, DeriveDataTypeable
38 ghc-options: -Wall -fno-warn-unused-do-bind
38 ghc-options: -Wall -fno-warn-unused-do-bind
39 HS-Source-Dirs: tests src
39 HS-Source-Dirs: tests src
40
40
@@ -42,13 +42,13 @@ Test-Suite TestMulticastInMemory
42 Type: exitcode-stdio-1.0
42 Type: exitcode-stdio-1.0
43 Main-Is: TestMulticastInMemory.hs
43 Main-Is: TestMulticastInMemory.hs
44 Build-Depends: base,
44 Build-Depends: base,
45− containers,
46 bytestring,
45 bytestring,
46+ containers,
47 data-accessor,
47 data-accessor,
48 mtl,
48 mtl,
49 transformers,
49 transformers,
50 ansi-terminal
50 ansi-terminal
51− extensions: EmptyDataDecls, OverloadedStrings, ForeignFunctionInterface, FlexibleContexts, BangPatterns, ScopedTypeVariables, DeriveDataTypeable
51+ extensions: OverloadedStrings, ForeignFunctionInterface, FlexibleContexts, DeriveDataTypeable
52 ghc-options: -Wall -fno-warn-unused-do-bind
52 ghc-options: -Wall -fno-warn-unused-do-bind
53 HS-Source-Dirs: tests src
53 HS-Source-Dirs: tests src
54
54
@@ -56,12 +56,12 @@ Test-Suite TestInMemory
56 Type: exitcode-stdio-1.0
56 Type: exitcode-stdio-1.0
57 Main-Is: TestInMemory.hs
57 Main-Is: TestInMemory.hs
58 Build-Depends: base,
58 Build-Depends: base,
59− containers,
60 bytestring,
59 bytestring,
60+ containers,
61 data-accessor,
61 data-accessor,
62 mtl,
62 mtl,
63 transformers,
63 transformers,
64 ansi-terminal
64 ansi-terminal
65− extensions: EmptyDataDecls, OverloadedStrings, ForeignFunctionInterface, FlexibleContexts, BangPatterns, ScopedTypeVariables, DeriveDataTypeable
65+ extensions: OverloadedStrings, ForeignFunctionInterface, FlexibleContexts, DeriveDataTypeable
66 ghc-options: -Wall -fno-warn-unused-do-bind
66 ghc-options: -Wall -fno-warn-unused-do-bind
67 HS-Source-Dirs: tests src
67 HS-Source-Dirs: tests src
network-transport-2/src/Network/Transport/Internal.hs+5−2
@@ -81,5 +81,8 @@ tlog msg = liftIO $ do
81-}
81-}
82
82
83-- | Safe version of 'toEnum'
83-- | Safe version of 'toEnum'
84−tryToEnum :: forall a. (Enum a, Bounded a) => Int -> Maybe a
84+tryToEnum :: (Enum a, Bounded a) => Int -> Maybe a
85−tryToEnum n = if fromEnum (minBound :: a) <= n && n <= fromEnum (maxBound :: a) then Just (toEnum n) else Nothing
85+tryToEnum = go minBound maxBound
86+ where
87+ go :: Enum b => b -> b -> Int -> Maybe b
88+ go lo hi n = if fromEnum lo <= n && n <= fromEnum hi then Just (toEnum n) else Nothing
network-transport-2/tests/TestTransport.hs+3−2
@@ -268,10 +268,11 @@ testCloseOneDirection transport numPings = do
268collect :: EndPoint -> Int -> IO [(ConnectionId, [[ByteString]])]
268collect :: EndPoint -> Int -> IO [(ConnectionId, [[ByteString]])]
269collect endPoint numEvents = go numEvents Map.empty Map.empty
269collect endPoint numEvents = go numEvents Map.empty Map.empty
270 where
270 where
271+ -- TODO: for more serious use of this function we'd need to make these arguments strict
271− go 0 !open !closed = if Map.null open
272+ go 0 open closed = if Map.null open
272 then return . Map.toList . Map.map reverse $ closed
273 then return . Map.toList . Map.map reverse $ closed
273 else fail "Open connections"
274 else fail "Open connections"
274− go !n !open !closed = do
275+ go n open closed = do
275 event <- receive endPoint
276 event <- receive endPoint
276 case event of
277 case event of
277 ConnectionOpened cid _ _ ->
278 ConnectionOpened cid _ _ ->