[Haskell] Probably a trivial thing for people knowing Haskell
Friedrich
frido at q-software-solutions.de
Sun Oct 19 11:25:14 EDT 2008
"Brandon S. Allbery KF8NH" <allbery at ece.cmu.edu> writes:
> On 2008 Oct 19, at 2:07, Friedrich wrote:
>> Howerver even if Strings are bad I can not see why they are hanging
>> around so long. I open a file a read it line by line and I close the
>> file so all read string are "garbage" and getting rid of them should
>> not be that hard or should it?
>
>
> If your code is too lazy, you have the whole file + the close
> operation hanging around in unevaluated thunks until you print the
> result and it all gets processed all at once. Laziness is a double-
> edged sword.
Ok to be more concrete is the laziness "hidden" here?
check_line line sum count =
let match = matchRegex regexp line
in case match of
Just strs -> (sum + read (head strs) :: Integer, count + 1)
Nothing -> (sum, count)
Regards
Friedrich
--
Q-Software Solutions GmbH; Sitz: Bruchsal; Registergericht: Mannheim
Registriernummer: HRB232138; Geschaeftsfuehrer: Friedrich Dominicus
More information about the Haskell
mailing list