[Haskell-beginners] Time interval calculation

Daniel Fischer daniel.is.fischer at web.de
Sat Mar 13 16:24:09 EST 2010


Am Samstag 13 März 2010 22:02:41 schrieb legajid:
> Sorry Daniel,
> i've seen your answer just after posting my reply.

Thought so. Happens to me often enough :)

> But i can't write !t1f <- gettime,

You can, and it's much like

let !t1 = ...

for the pure calculation, it evaluates t1f to the outermost constructor. If 
deeper evaluation is needed, like for pure values, you have to use the 
appropriate forcing strategy.

    !a <- mx

is less important for IO than for other monads, though, since IO imposes a 
fair amount of sequencing. In particular, the sequencing of IO makes

    !t1f <- gettime

superfluous, since all that could be delayed in gettime is the 
transformation of the timestamp retrieved from the system clock to the 
ClockTime datatype, the timestamp is retrieved at the exact point in the 
IO-sequence.

> nor t1f <- !gettime;

I'm not sure whether you can write that, but it wouldn't be what you want 
anyway. If that's legal BangPattern syntax, it says "evaluate gettime to 
the outermost constructor", which is far less than we need to evaluate 
gettime to bind its result to a name.

> because it's an
> IO ? Your method is a good help form me.
>
> Thanks,
> Didier



More information about the Beginners mailing list