Haskell Timeout Calculation Distribution

I am trying to write a safe time evaluation function in Haskell. The code is as follows

import System.Timeout

compute, compute' :: Int -> Int
compute  i = sum [1..300000 + i]
compute' i = last $ repeat i

timedComp :: Int -> a -> IO (Maybe a)
timedComp timeLeft toCompute =
        timeout timeLeft go
    where
        go = toCompute `seq` return toCompute

main = do
    res <- timedComp 10000 (compute 0)
    print res

    res' <- timedComp 10000 (compute' 0)
    print res'

(I know that I am only evaluating WHNF.)

When I run main, I get only one "Nothing" message in the output, and then the program freezes. I tried to compile and run a multithreaded program, but that does not help. Tried both GHC 7.6.3 and 7.8.3. Any suggestions?

+4
source share
1 answer

GHC- Haskell : . , , , , .

: compute' i = last $ repeat i , , , , GHC , - GHC Core f x = f x. .

-fno-omit-yields . , GHC .

+3

Source: https://habr.com/ru/post/1620393/


All Articles