You're welcome!

On 7/16/14, 10:13 AM, Sibi Prabakaran wrote:
Thanks Gabriel.


On Friday, July 11, 2014 3:08:57 AM UTC+5:30, Gabriel Gonzalez wrote:

    You can use `Control.Monad.void`:

        void :: Functor m => m a -> m ()
        void m = fmap (\_ -> ()) m

    Another equivalent way to do this is:

        (p >> return ())

    ... where `p` is the `Producer` whose return value you want to
    swallow.  This actually works for any `Monad`, not just `Producer`.

    On Jul 10, 2014 11:52 AM, "Sibi Prabakaran" <[email protected]
    <javascript:>> wrote:


        I have the following piece of code which typechecks perfectly:

        import           Control.Applicative ((<*))
        import           Control.Monad (liftM)
        import           Data.Attoparsec.Text
        import           Pipes
        import           Pipes.Attoparsec (parsed, ParsingError)
        import qualified Pipes.Prelude as P
        import Pipes.Text.IO <http://Pipes.Text.IO> (fromHandle)
        import qualified System.IO as IO

        type LinkID = Int

        data Link = Link {
          lid :: LinkID,
          llength :: Int
          }

        data Snap = Snap {
          slid :: LinkID,
          slength :: Int
          }

        getSnap
          :: Monad m
          => Int
          -> Producer Link m ()
          -> Producer Snap m ()
          -> Producer (LinkID, [Snap]) m ()
        getSnap n lks snp = do
          snp' <- lift (P.toListM snp)
          lks >-> P.filter (\x -> lid x > n)
                >-> P.map (\x -> (lid x, filter (\y -> lid x == slid
        y) snp'))

        drawData :: (LinkID, [Snap]) -> IO ()
        drawData = undefined

        linkFile = "some file path"
        snapshotFile = "some file path"

        parseLink :: Parser Link
        parseLink = undefined

        snapshotParser :: Parser Snap
        snapshotParser = undefined

        Note that some parts of the code are defined as undefined for
        the sake of brevity. Now when I include main function it
        doesn't typecheck:

        main = IO.withFile linkFile IO.ReadMode $ \linkHandle ->
          IO.withFile snapshotFile IO.ReadMode $ \snapHandle ->
        runEffect $
          for (getSnap 2 (parsed (parseLink <* endOfLine) (fromHandle
        linkHandle))
               (parsed (snapshotParser <* endOfLine) (fromHandle
        snapHandle))) $ \d ->
          lift (drawData d)

        The error:

        Expected type: Producer Link IO ()
              Actual type: Producer
                             Link
                             IO
                             (Either (ParsingError, Producer
        Data.Text.Internal.Text IO ()) ())
            In the return type of a call of `parsed'
            In the second argument of `getSnap', namely

        Now, in order to fix this problem, I change getSnap function:

        getSnap
          :: Monad m
          => Int
          -> Producer Link m r
          -> Producer Snap m r
          -> Producer (LinkID, [Snap]) m r
        getSnap n lks snp = do
          snp' <- lift (P.toListM snp)
          lks >-> P.filter (\x -> lid x > n)
                >-> P.map (\x -> (lid x, filter (\y -> lid x == slid
        y) snp'))

        Now, it seems P.toListM only operates on Producer a m () so, I
        want to convert Producer a m r to that. What is the
        recommended way of solving this problem ?
-- You received this message because you are subscribed to the
        Google Groups "Haskell Pipes" group.
        To unsubscribe from this group and stop receiving emails from
        it, send an email to [email protected]
        <javascript:>.
        To post to this group, send email to
        [email protected] <javascript:>.

--
You received this message because you are subscribed to the Google Groups "Haskell Pipes" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>.

--
You received this message because you are subscribed to the Google Groups "Haskell 
Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].

Reply via email to