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?
GHC- Haskell : . , , , , .
: compute' i = last $ repeat i , , , , GHC , - GHC Core f x = f x. .
compute' i = last $ repeat i
f x = f x
-fno-omit-yields . , GHC .
-fno-omit-yields
Source: https://habr.com/ru/post/1620393/More articles:Mongoose: save nested JSON with various schemas - jsonUnable to change loop variable in lua - luaCreating an instance of a class in TypeScript - typescriptUsing generated code in unit tests with maven clean build? - javaCreating a complex event using Moq in C # - c #Segmentation error Strtok_r - cJava HTTP Client outputs empty JSON - javaDjango forms unit tests with ForeignKey - djangomap scaling geocoropleth dc.js - svgUsing NSLayoutConstraint in a subzone in combination with an affine transformation - iosAll Articles