[Haskell-cafe] Re: Memoizing partially evaluated computations.
Luke Palmer
lrpalmer at gmail.com
Wed Mar 18 23:24:58 EDT 2009
On Wed, Mar 18, 2009 at 6:21 AM, Chung-chieh Shan
<ccshan at post.harvard.edu>wrote:
> Sebastiaan Visser <sfvisser at cs.uu.nl> wrote in article <
> D86A7D11-F95F-4A27-A13C-2D78AFDA2E02 at 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
Um, just to clarify, this code is exactly equivalent to the original,
including sharing behavior. The only time a let (or where) clause changes
sharing is if the variable is used more than once in the body.
Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090318/8e9c8d44/attachment.htm
More information about the Haskell-Cafe
mailing list