[Haskell-beginners] How to display a time difference?

Sean Lee sean.ysl at gmail.com
Wed Mar 18 06:54:09 EDT 2009


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
>    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
>



-- 
Sean Lee
PhD Student
Programming Language and Systems Research Group
School of Computer Science and Engineering
University of New South Wales
http://www.cse.unsw.edu.au/~seanl


More information about the Beginners mailing list