Sebastiaan Visser <sfvis...@cs.uu.nl> wrote in article <d86a7d11-f95f-4a27-a13c-2d78afda2...@cs.uu.nl> in gmane.comp.lang.haskell.cafe: > Suppose I have a list of IO computations that depends on a few very > time consuming pure operations. The pure operations are not dependent > on the real world: > > > computation :: [IO Int] > > computation = [ > > smallIOfunc timeConsumingPureOperation0 > > , smallIOfunc timeConsumingPureOperation1 > > , smallIOfunc timeConsumingPureOperation2 > > , smallIOfunc timeConsumingPureOperation3 > > ] > > where smallIOfunc a = print a >> return a
I take it that, because you "do not really have the control to change things `deep' inside the code", it is not an option to redefine computation = [ smallIOfunc x0 , smallIOfunc x1 , smallIOfunc x2 , smallIOfunc x3 ] where smallIOfunc a = print a >> return a x0 = timeConsumingPureOperation0 x1 = timeConsumingPureOperation1 x2 = timeConsumingPureOperation2 x3 = timeConsumingPureOperation3 Can you define smallIOfunc to be more polymorphic in the monad? That is, can you define a class of monads (MonadBehavior, let's call it) that contains member functions for operations (such as print) you want to perform in smallIOfunc, then write smallIOfunc to be polymorphic over such a monad? If so, you can then implement two instances of this class: one for IO and one for a term representation of behavior. -- Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig Who would have thought LISP would come back to life. Steve Bourne, in an interview about Bourne Shell. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe