[Haskell-cafe] lazily-loaded structures

Luke Palmer lrpalmer at gmail.com
Fri Jan 1 20:37:50 EST 2010

On Fri, Jan 1, 2010 at 6:24 PM, Jeff Davis <pgsql at j-davis.com> wrote:
> I wonder if it might be useful to approach it like a virtual memory
> system. Searching for a value that hasn't been loaded into the structure
> would raise an exception, which would then be caught, handled by using
> normal (safe) IO, and then the computation could be retried.
> Is that idea crazy, or does it have some merit?

No, pretty much crazy.  Exceptions are just as impure as any other effect.

To capture network computations, abstract them out, into eg. a type
"Network a" which represents values which depend on network data.  It
would naturally be monadic, but you can restrict the operations so
that Network can only do specific things - eg. reading, not writing,
not overwritng your hard drive, not throwing exceptions (or throwing
them if you want it to), etc.

This is the typical method of abstracting over IO in Haskell.  As a
sort of dual to the OO way, where you start with simple operations and
add features, we start with "anything" (the IO monad) and take away
features until we have something we can reason about.


More information about the Haskell-Cafe mailing list