[Haskell-beginners] A first try

Heinrich Apfelmus apfelmus at quantentunnel.de
Wed Jun 29 10:30:47 CEST 2011


David Place wrote:
> On Jun 28, 2011, at 8:39 AM, Heinrich Apfelmus wrote:
> 
>> There is still a return value, but  withFile  makes sure that it's
>> evaluated to WHNF. If you choose a = (), then you're fine,
>> otherwise it's not entirely foolproof.
> 
> Yes, I was wondering about this.  Since it is still possible to get
> in trouble in exactly the same way, why is this an improvement over
> withFile?  If you return () from withFile, you have the same benefit.

The improvement is that my variant of  withFile  absorbs a few more 
moving parts, namely calling  hGetContents  and forcing the result.

It is still possible to write programs that return unexpected _|_, but 
they violate a clear conceptual guideline ("only fully evaluated values 
may escape the scope of  withFile "). Granted, Iteratees make it 
impossible to write such programs, but they come with the terrible price 
of code duplication.


Best regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com




More information about the Beginners mailing list