[Haskell-beginners] How to display a time difference?
daniel.is.fischer at web.de
Wed Mar 18 07:00:56 EDT 2009
Am Mittwoch, 18. März 2009 11:54 schrieb Sean Lee:
> You get some random values? or no change at all on the state?
> On Wed, Mar 18, 2009 at 9:45 PM, Colin Paul Adams
> <colin at colina.demon.co.uk> wrote:
> >>>>>> "Sean" == Sean Lee <sean.ysl at gmail.com> writes:
> > Sean> Hi Colin The following code probably would do what I wanted
> > Sean> to do.
> > Sean> play_move :: IORef Game_state -> IO () play_move
> > Sean> game_state_ior = do (_, state, _) <- readIORef
> > Sean> game_state_ior putStr "Playing AI: " start_time <-
> > Sean> getCurrentTime let move = recommended_move state end_time <-
> > Sean> move `seq` (modifyIORef game_state_ior $!
> > Sean> update_interactive_from_move move) `seq` getCurrentTime
that should probably have been
move `seq` (modifyIORef game_state_ior $! ... ) >> getCurrentTime
value `seq` ioAction1 `seq` ioAction2
doesn't execute ioAction1.
> > Sean> putStrLn $ show $ (diffUTCTime end_time start_time)
> > Sean> Due to the non-strictness of Haskell, the evaluation of the
> > Sean> expressions between start_time and end_time is deferred
> > Sean> until there is a need. By using `seq` and ($!), the
> > Sean> strictness can be forced.
> > It certainly causes a time delay, and a non-zero time is printed, but
> > the state doesn't get modified correctly now.
> > ??
> > I will ponder Daniel's suggestion.
> > --
> > Colin Adams
> > Preston Lancashire
More information about the Beginners