on master help sign in
remove the numeric instances
commit0810ad78e65cb119994c170c473651e401d57359 authorHarendra Kumar <harendra.kumar@gmail.com> dateSun 22 Apr 2018, 23:23 (9 years ago) parente411ab6
3 files changed+3−84
Changelog.md+3−1 src/Streamly/Streams.hs−50 test/Main.hs−33
Changelog.md+3−1
@@ -28,8 +28,10 @@
2828 Stream types may have to be changed or type combinators may have to be added
2929 or removed to adapt to this change.
3030* Change the type of `foldrM` to make it consistent with `foldrM` in base.
31−* Remove the MonadError instance as it was not working correctly for the
31+* Remove the MonadError instance as it was not working correctly for
3232 parallel compositions. Use MonadThrow instead for error propagation.
33+* Remove Num/Fractional/Floating instances as they are not very useful. Use
34+ `fmap` and `liftA2` instead.
3335
3436### Deprecations
3537* Deprecate and rename the following symbols:
src/Streamly/Streams.hs−50
@@ -103,7 +103,6 @@ module Streamly.Streams
103103 )
104104where
105105
106−import Control.Applicative (liftA2)
107106import Control.Monad (ap)
108107import Control.Monad.Base (MonadBase (..), liftBaseDefault)
109108import Control.Monad.Catch (MonadThrow, throwM)
@@ -307,47 +306,6 @@ instance (MonadState s m CONSTRAINT) => MonadState s (STREAM m) where { \
307306 put x = lift (put x); \
308307 state k = lift (state k) }
309308
310−#define NUMERIC_COMMON_INSTANCES(STREAM,CONSTRAINT) \
311−instance (Monad m, Num a CONSTRAINT) => Num (STREAM m a) where { \
312− fromInteger n = pure (fromInteger n); \
313− \
314− negate = fmap negate; \
315− abs = fmap abs; \
316− signum = fmap signum; \
317− \
318− (+) = liftA2 (+); \
319− (*) = liftA2 (*); \
320− (-) = liftA2 (-) }; \
321− \
322−instance (Monad m, Fractional a CONSTRAINT) => Fractional (STREAM m a) where {\
323− fromRational n = pure (fromRational n); \
324− \
325− recip = fmap recip; \
326− \
327− (/) = liftA2 (/) }; \
328− \
329−instance (Monad m, Floating a CONSTRAINT) => Floating (STREAM m a) where { \
330− pi = pure pi; \
331− \
332− exp = fmap exp; \
333− sqrt = fmap sqrt; \
334− log = fmap log; \
335− sin = fmap sin; \
336− tan = fmap tan; \
337− cos = fmap cos; \
338− asin = fmap asin; \
339− atan = fmap atan; \
340− acos = fmap acos; \
341− sinh = fmap sinh; \
342− tanh = fmap tanh; \
343− cosh = fmap cosh; \
344− asinh = fmap asinh; \
345− atanh = fmap atanh; \
346− acosh = fmap acosh; \
347− \
348− (**) = liftA2 (**); \
349− logBase = liftA2 logBase }
350−
351309------------------------------------------------------------------------------
352310-- SerialT
353311------------------------------------------------------------------------------
@@ -442,7 +400,6 @@ instance Monad m => Monad (SerialT m) where
442400
443401MONAD_APPLICATIVE_INSTANCE(SerialT,)
444402MONAD_COMMON_INSTANCES(SerialT,)
445−NUMERIC_COMMON_INSTANCES(SerialT,)
446403
447404------------------------------------------------------------------------------
448405-- CoserialT
@@ -535,7 +492,6 @@ instance Monad m => Monad (CoserialT m) where
535492
536493MONAD_APPLICATIVE_INSTANCE(CoserialT,)
537494MONAD_COMMON_INSTANCES(CoserialT,)
538−NUMERIC_COMMON_INSTANCES(CoserialT,)
539495
540496------------------------------------------------------------------------------
541497-- CoparallelT
@@ -648,7 +604,6 @@ instance MonadParallel m => Monad (CoparallelT m) where
648604
649605MONAD_APPLICATIVE_INSTANCE(CoparallelT,MONADPARALLEL)
650606MONAD_COMMON_INSTANCES(CoparallelT, MONADPARALLEL)
651−NUMERIC_COMMON_INSTANCES(CoparallelT, MONADPARALLEL)
652607
653608------------------------------------------------------------------------------
654609-- ParallelT
@@ -734,7 +689,6 @@ instance MonadParallel m => Monad (ParallelT m) where
734689
735690MONAD_APPLICATIVE_INSTANCE(ParallelT,MONADPARALLEL)
736691MONAD_COMMON_INSTANCES(ParallelT, MONADPARALLEL)
737−NUMERIC_COMMON_INSTANCES(ParallelT, MONADPARALLEL)
738692
739693------------------------------------------------------------------------------
740694-- Serially Zipping Streams
@@ -785,8 +739,6 @@ instance IsStream ZipSerial where
785739 toStream = getZipSerial
786740 fromStream = ZipSerial
787741
788−NUMERIC_COMMON_INSTANCES(ZipSerial,)
789−
790742------------------------------------------------------------------------------
791743-- Parallely Zipping Streams
792744------------------------------------------------------------------------------
@@ -835,8 +787,6 @@ instance IsStream ZipParallel where
835787 toStream = getZipParallel
836788 fromStream = ZipParallel
837789
838−NUMERIC_COMMON_INSTANCES(ZipParallel,MONADPARALLEL)
839−
840790-------------------------------------------------------------------------------
841791-- Type adapting combinators
842792-------------------------------------------------------------------------------
test/Main.hs−33
@@ -277,11 +277,6 @@ main = hspec $ do
277277 it "Nests two streams using applicative async composition" nestTwoAsyncApp
278278 it "Nests two streams using applicative parallel composition" nestTwoParallelApp
279279
280− it "Nests two streams using Num serial composition" nestTwoSerialNum
281− it "Nests two streams using Num interleaved composition" nestTwoInterleavedNum
282− it "Nests two streams using Num async composition" nestTwoAsyncNum
283− it "Nests two streams using Num parallel composition" nestTwoParallelNum
284−
285280 ---------------------------------------------------------------------------
286281 -- TBD Bind and Bind combinations
287282 ---------------------------------------------------------------------------
@@ -402,13 +397,6 @@ nestTwoSerialApp =
402397 in toListSerial ((+) <$> s1 <*> s2)
403398 `shouldReturn` ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
404399
405−nestTwoSerialNum :: Expectation
406−nestTwoSerialNum =
407− let s1 = foldMapWith (<>) return [1..4]
408− s2 = foldMapWith (<>) return [5..8]
409− in toListSerial (s1 + s2)
410− `shouldReturn` ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
411−
412400nestTwoInterleaved :: Expectation
413401nestTwoInterleaved =
414402 let s1 = foldMapWith (<>) return [1..4]
@@ -426,13 +414,6 @@ nestTwoInterleavedApp =
426414 in toListInterleaved ((+) <$> s1 <*> s2)
427415 `shouldReturn` ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
428416
429−nestTwoInterleavedNum :: Expectation
430−nestTwoInterleavedNum =
431− let s1 = foldMapWith (<>) return [1..4]
432− s2 = foldMapWith (<>) return [5..8]
433− in toListInterleaved (s1 + s2)
434− `shouldReturn` ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
435−
436417nestTwoAsync :: Expectation
437418nestTwoAsync =
438419 let s1 = foldMapWith (<>) return [1..4]
@@ -451,13 +432,6 @@ nestTwoAsyncApp =
451432 in (toListAsync ((+) <$> s1 <*> s2) >>= return . sort)
452433 `shouldReturn` sort ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
453434
454−nestTwoAsyncNum :: Expectation
455−nestTwoAsyncNum =
456− let s1 = foldMapWith (<>) return [1..4]
457− s2 = foldMapWith (<>) return [5..8]
458− in (toListAsync (s1 + s2) >>= return . sort)
459− `shouldReturn` sort ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
460−
461435nestTwoParallel :: Expectation
462436nestTwoParallel =
463437 let s1 = foldMapWith (<>) return [1..4]
@@ -476,13 +450,6 @@ nestTwoParallelApp =
476450 in (toListParallel ((+) <$> s1 <*> s2) >>= return . sort)
477451 `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
478452
479−nestTwoParallelNum :: Expectation
480−nestTwoParallelNum =
481− let s1 = foldMapWith (<>) return [1..4]
482− s2 = foldMapWith (<>) return [5..8]
483− in (toListParallel (s1 + s2) >>= return . sort)
484− `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
485−
486453timed :: MonadIO (t IO) => Int -> t IO Int
487454timed x = liftIO (threadDelay (x * 100000)) >> return x
488455