1

In the pipes package, the tutorial Control.Pipes.Tutorial [1] shows how to "vertically stack" pipe components using the monad >> operator.

How would I go about doing that with Control.Frame?

For example, using the definitions from the Control.Frame tutorial:

source1 = fromList [1..10]
source2 = fromList [30..40]

-- combine two sources:

runFrame $ printer <-< (source1 ??? source2)

-- combine two transformers:

runFrame $ printer <-< (take' 3 ??? take' 2) <-< fromList [1..]

Using >> here for ??? doesn't typecheck.

[1] http://hackage.haskell.org/packages/archive/pipes/latest/doc/html/Control-Pipe-Tutorial.html#g:4

Update: Here is a paste of what I've been trying: http://hpaste.org/77986

It looks like close is the problem -- see the function bar8 in the above paste. The frames are composable with >> if I don't explicitly close them. Of course, I eventually need to close them. Hmmm....

Davorak
  • 7,362
  • 1
  • 38
  • 48
ErikR
  • 51,541
  • 9
  • 73
  • 124

1 Answers1

1

A Frame isn't a monad, it's an indexed monad. This means that the normal monad operators won't work, and you have to import the indexed versions of them. According to the tutorial, this means adding the following to the top of your file:

{-# LANGUAGE RebindableSyntax #-}

import Control.Frame
import Control.IMonad.Do
import Control.IMonad.Trans
import Prelude hiding (Monad(..))
dflemstr
  • 25,947
  • 5
  • 70
  • 105
  • I am running the tutorial code, and I have those imports at the top of my file. So what would be the analogous operator for indexed monads? Or what would be the fully qualified name of the function I need to use to vertically stack the Frame components? – ErikR Nov 19 '12 at 14:45
  • It should work with the code that you posted, since the operator has exactly the same name. Please post the error that you receive upon compilation for further assistance. – dflemstr Nov 19 '12 at 19:43
  • See the update to the problem - I've included the code I'm working with. – ErikR Nov 21 '12 at 02:12
  • Well, you found it out by yourself. If the first frame closes the resource, the second frame can't use it any more. – dflemstr Nov 21 '12 at 12:30