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

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Sat Jan 23 16:21:31 EST 2010


On Jan 23, 2010, at 16:08 , Daniel Fischer wrote:
> Am Samstag 23 Januar 2010 21:31:47 schrieb Adrian Adshead:
>> I have two questions to try and clarify my understanding.
>>
>> 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)
>
> Excluding unsafePerformIO, only in a very weak sense.

And, while you could do the dance to make unsafePerformIO available  
and use it, the aggressive optimizations the compiler makes on pure  
code can lead to extremely unexpected results.

>> 2) Is it possible to have a function which evaluates any IO Action
>> within the body and have a non-IO return value?
>> (ie is    f :: a -> b     possible while evaluating any IO Action
>> within the body.)
>
> Assuming by evaluating you mean executing and not
>
> (return 5 >> return 6) ~> IO (\s -> (s,6))
>
> , no, that's not possible.

Again, barring unsafePerformIO, and that will bite you if you use it  
without knowing exactly what you're doing and why and *forcing* the  
compiler to agree with you.

(As it turns out, you can often figure out the implementation details  
of your chosen compiler's IO and force the issue.  But any code that  
do so *is* reimplementing unsafePerformIO, and you will pay dearly.)

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/beginners/attachments/20100123/ad5e0dc8/PGP.bin


More information about the Beginners mailing list