[Haskell-beginners] Re: Re: testing and the culture of Haskell

Isaac Dupree ml at isaac.cedarswampstudios.org
Sat Jan 23 18:39:16 EST 2010


Adrian Adshead wrote:
> 1) Is it possible to have a function with an IO Action as an input
> parameter (and not just ignore the parameter) and have a non-IO
> return value?
> (ie is     f :: IO a -> b    possible without ignoring the IO a)

pretty much no, but consider, we can return a data structure constructed 
out of those IOs, without actually learning anything about what actions 
they are intended to do. For example:

f :: IO a -> [IO a]
f io = iterate (\io2 -> (io2 >> io2)) io

returns a list, in which the first action would do the IO once, the 
second would do it twice, the third element would do it four times, the 
fourth element, eight times, and so forth.

Obviously, it is only occasionally useful to do something strange like that.

-Isaac


More information about the Beginners mailing list