Skip to content

Commit 4bc714f

Browse files
Remove MonadIO constraint from pure array getIndices
1 parent c8e46a7 commit 4bc714f

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/Streamly/Internal/Data/Array/Foreign.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ import qualified Streamly.Internal.Data.Stream.StreamD as D
150150
import qualified Streamly.Internal.Data.Unfold as Unfold
151151
import qualified Streamly.Internal.Data.Ring.Foreign as RB
152152

153-
154-
155153
-------------------------------------------------------------------------------
156154
-- Construction
157155
-------------------------------------------------------------------------------
@@ -462,9 +460,10 @@ getIndex arr i =
462460
--
463461
-- /Pre-release/
464462
{-# INLINE getIndices #-}
465-
getIndices :: (MonadIO m, Storable a)
466-
=> SerialT m Int -> Unfold m (Array a) a
467-
getIndices st = Unfold.lmap A.unsafeThaw (MA.getIndices st)
463+
getIndices :: (Monad m, Storable a) => SerialT m Int -> Unfold m (Array a) a
464+
getIndices (SerialT stream) =
465+
let unf = MA.getIndicesD (return . unsafeInlineIO) $ D.fromStreamK stream
466+
in Unfold.lmap A.unsafeThaw unf
468467

469468
-- | Unfolds @(from, then, to, array)@ generating a finite stream whose first
470469
-- element is the array value from the index @from@ and the successive elements

src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ module Streamly.Internal.Data.Array.Foreign.Mut.Type
114114
, getIndex
115115
, getIndexUnsafe
116116
, getIndices
117+
, getIndicesD
117118
-- , getFromThenTo
118119
, getIndexRev
119120

@@ -1092,9 +1093,9 @@ data GetIndicesState contents start end st =
10921093
--
10931094
-- /Pre-release/
10941095
{-# INLINE getIndicesD #-}
1095-
getIndicesD :: (MonadIO m, Storable a) =>
1096-
D.Stream m Int -> Unfold m (Array a) a
1097-
getIndicesD (D.Stream stepi sti) = Unfold step inject
1096+
getIndicesD :: (Monad m, Storable a) =>
1097+
(forall b. IO b -> m b) -> D.Stream m Int -> Unfold m (Array a) a
1098+
getIndicesD liftio (D.Stream stepi sti) = Unfold step inject
10981099

10991100
where
11001101

@@ -1106,16 +1107,16 @@ getIndicesD (D.Stream stepi sti) = Unfold step inject
11061107
r <- stepi defState st
11071108
case r of
11081109
D.Yield i s -> do
1109-
x <- liftIO $ getIndexPtr start end i
1110+
x <- liftio $ getIndexPtr start end i
11101111
return $ D.Yield x (GetIndicesState contents start end s)
11111112
D.Skip s -> return $ D.Skip (GetIndicesState contents start end s)
11121113
D.Stop -> do
1113-
liftIO $ touch contents
1114+
liftio $ touch contents
11141115
return D.Stop
11151116

11161117
{-# INLINE getIndices #-}
11171118
getIndices :: (MonadIO m, Storable a) => SerialT m Int -> Unfold m (Array a) a
1118-
getIndices (SerialT stream) = getIndicesD $ D.fromStreamK stream
1119+
getIndices (SerialT stream) = getIndicesD liftIO $ D.fromStreamK stream
11191120

11201121
-------------------------------------------------------------------------------
11211122
-- Subarrays

0 commit comments

Comments
 (0)