on master help sign in
remove the numeric instances
0810ad7Harendra Kumar
Changelog.md+3−1
@@ -28,8 +28,10 @@
28 Stream types may have to be changed or type combinators may have to be added
28 Stream types may have to be changed or type combinators may have to be added
29 or removed to adapt to this change.
29 or removed to adapt to this change.
30* Change the type of `foldrM` to make it consistent with `foldrM` in base.
30* 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
32 parallel compositions. Use MonadThrow instead for error propagation.
32 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.
33
35
34### Deprecations
36### Deprecations
35* Deprecate and rename the following symbols:
37* Deprecate and rename the following symbols:
src/Streamly/Streams.hs−50
@@ -103,7 +103,6 @@ module Streamly.Streams
103 )
103 )
104where
104where
105
105
106−import Control.Applicative (liftA2)
107import Control.Monad (ap)
106import Control.Monad (ap)
108import Control.Monad.Base (MonadBase (..), liftBaseDefault)
107import Control.Monad.Base (MonadBase (..), liftBaseDefault)
109import Control.Monad.Catch (MonadThrow, throwM)
108import Control.Monad.Catch (MonadThrow, throwM)
@@ -307,47 +306,6 @@ instance (MonadState s m CONSTRAINT) => MonadState s (STREAM m) where { \
307 put x = lift (put x); \
306 put x = lift (put x); \
308 state k = lift (state k) }
307 state k = lift (state k) }
309
308
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−
351------------------------------------------------------------------------------
309------------------------------------------------------------------------------
352-- SerialT
310-- SerialT
353------------------------------------------------------------------------------
311------------------------------------------------------------------------------
@@ -442,7 +400,6 @@ instance Monad m => Monad (SerialT m) where
442
400
443MONAD_APPLICATIVE_INSTANCE(SerialT,)
401MONAD_APPLICATIVE_INSTANCE(SerialT,)
444MONAD_COMMON_INSTANCES(SerialT,)
402MONAD_COMMON_INSTANCES(SerialT,)
445−NUMERIC_COMMON_INSTANCES(SerialT,)
446
403
447------------------------------------------------------------------------------
404------------------------------------------------------------------------------
448-- CoserialT
405-- CoserialT
@@ -535,7 +492,6 @@ instance Monad m => Monad (CoserialT m) where
535
492
536MONAD_APPLICATIVE_INSTANCE(CoserialT,)
493MONAD_APPLICATIVE_INSTANCE(CoserialT,)
537MONAD_COMMON_INSTANCES(CoserialT,)
494MONAD_COMMON_INSTANCES(CoserialT,)
538−NUMERIC_COMMON_INSTANCES(CoserialT,)
539
495
540------------------------------------------------------------------------------
496------------------------------------------------------------------------------
541-- CoparallelT
497-- CoparallelT
@@ -648,7 +604,6 @@ instance MonadParallel m => Monad (CoparallelT m) where
648
604
649MONAD_APPLICATIVE_INSTANCE(CoparallelT,MONADPARALLEL)
605MONAD_APPLICATIVE_INSTANCE(CoparallelT,MONADPARALLEL)
650MONAD_COMMON_INSTANCES(CoparallelT, MONADPARALLEL)
606MONAD_COMMON_INSTANCES(CoparallelT, MONADPARALLEL)
651−NUMERIC_COMMON_INSTANCES(CoparallelT, MONADPARALLEL)
652
607
653------------------------------------------------------------------------------
608------------------------------------------------------------------------------
654-- ParallelT
609-- ParallelT
@@ -734,7 +689,6 @@ instance MonadParallel m => Monad (ParallelT m) where
734
689
735MONAD_APPLICATIVE_INSTANCE(ParallelT,MONADPARALLEL)
690MONAD_APPLICATIVE_INSTANCE(ParallelT,MONADPARALLEL)
736MONAD_COMMON_INSTANCES(ParallelT, MONADPARALLEL)
691MONAD_COMMON_INSTANCES(ParallelT, MONADPARALLEL)
737−NUMERIC_COMMON_INSTANCES(ParallelT, MONADPARALLEL)
738
692
739------------------------------------------------------------------------------
693------------------------------------------------------------------------------
740-- Serially Zipping Streams
694-- Serially Zipping Streams
@@ -785,8 +739,6 @@ instance IsStream ZipSerial where
785 toStream = getZipSerial
739 toStream = getZipSerial
786 fromStream = ZipSerial
740 fromStream = ZipSerial
787
741
788−NUMERIC_COMMON_INSTANCES(ZipSerial,)
789−
790------------------------------------------------------------------------------
742------------------------------------------------------------------------------
791-- Parallely Zipping Streams
743-- Parallely Zipping Streams
792------------------------------------------------------------------------------
744------------------------------------------------------------------------------
@@ -835,8 +787,6 @@ instance IsStream ZipParallel where
835 toStream = getZipParallel
787 toStream = getZipParallel
836 fromStream = ZipParallel
788 fromStream = ZipParallel
837
789
838−NUMERIC_COMMON_INSTANCES(ZipParallel,MONADPARALLEL)
839−
840-------------------------------------------------------------------------------
790-------------------------------------------------------------------------------
841-- Type adapting combinators
791-- Type adapting combinators
842-------------------------------------------------------------------------------
792-------------------------------------------------------------------------------
test/Main.hs−33
@@ -277,11 +277,6 @@ main = hspec $ do
277 it "Nests two streams using applicative async composition" nestTwoAsyncApp
277 it "Nests two streams using applicative async composition" nestTwoAsyncApp
278 it "Nests two streams using applicative parallel composition" nestTwoParallelApp
278 it "Nests two streams using applicative parallel composition" nestTwoParallelApp
279
279
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−
285 ---------------------------------------------------------------------------
280 ---------------------------------------------------------------------------
286 -- TBD Bind and Bind combinations
281 -- TBD Bind and Bind combinations
287 ---------------------------------------------------------------------------
282 ---------------------------------------------------------------------------
@@ -402,13 +397,6 @@ nestTwoSerialApp =
402 in toListSerial ((+) <$> s1 <*> s2)
397 in toListSerial ((+) <$> s1 <*> s2)
403 `shouldReturn` ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
398 `shouldReturn` ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
404
399
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−
412nestTwoInterleaved :: Expectation
400nestTwoInterleaved :: Expectation
413nestTwoInterleaved =
401nestTwoInterleaved =
414 let s1 = foldMapWith (<>) return [1..4]
402 let s1 = foldMapWith (<>) return [1..4]
@@ -426,13 +414,6 @@ nestTwoInterleavedApp =
426 in toListInterleaved ((+) <$> s1 <*> s2)
414 in toListInterleaved ((+) <$> s1 <*> s2)
427 `shouldReturn` ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
415 `shouldReturn` ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
428
416
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−
436nestTwoAsync :: Expectation
417nestTwoAsync :: Expectation
437nestTwoAsync =
418nestTwoAsync =
438 let s1 = foldMapWith (<>) return [1..4]
419 let s1 = foldMapWith (<>) return [1..4]
@@ -451,13 +432,6 @@ nestTwoAsyncApp =
451 in (toListAsync ((+) <$> s1 <*> s2) >>= return . sort)
432 in (toListAsync ((+) <$> s1 <*> s2) >>= return . sort)
452 `shouldReturn` sort ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
433 `shouldReturn` sort ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
453
434
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−
461nestTwoParallel :: Expectation
435nestTwoParallel :: Expectation
462nestTwoParallel =
436nestTwoParallel =
463 let s1 = foldMapWith (<>) return [1..4]
437 let s1 = foldMapWith (<>) return [1..4]
@@ -476,13 +450,6 @@ nestTwoParallelApp =
476 in (toListParallel ((+) <$> s1 <*> s2) >>= return . sort)
450 in (toListParallel ((+) <$> s1 <*> s2) >>= return . sort)
477 `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
451 `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
478
452
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−
486timed :: MonadIO (t IO) => Int -> t IO Int
453timed :: MonadIO (t IO) => Int -> t IO Int
487timed x = liftIO (threadDelay (x * 100000)) >> return x
454timed x = liftIO (threadDelay (x * 100000)) >> return x
488
455