[Haskell-beginners] calling inpure functions from pure code

Emmanuel Touzery etouzery at gmail.com
Fri Oct 12 16:09:00 CEST 2012


Hi,

> Then I have a "second pass" in the caller function, where for programs 
> which have a link, I would fetch the extra page, and call a second 
> function, which will fill in the extra data (thankfully if pictures 
> are present I only store their URL so it would stop there, no need for 
> a third pass for pictures).
>
> It annoys me that the first function returns "incomplete" objects... 
> It somehow feels wrong. 

I just realized i have the wrong way of thinking about it, in Haskell 
data is immutable therefore the first function wouldn't return 
incomplete "objects" that would be completed later: the second function 
will re-create completely the data anyway. So I would have duplicate 
data structures, once without the extra data, once with. Or something 
like that.

>> And otherwise I guess this is the policy when writing Haskell code:
>> absolutely avoid spreading impure/IO tainted code, even if it maybe
>> negatively affects the general structure of the program?
> There should be a reason for separating pure and impure code. If your
> code doesn't get easier to reason about or more reusable, than
> there's little reason for separation.

Yes.. I thought the goal is to strive for as much pure code as possible 
(which is easier to test and so on), but in this case (and obviously 
it's a small program) it doesn't seem tractable. I wonder what is the 
ratio pure/impure in bigger programs.

Thank you...

Emmanuel



More information about the Beginners mailing list