0 votes
1 view
in AI and Deep Learning by (44.8k points)

I'm writing a game AI in Haskell, and I want to search the game state tree for a specified amount of time (i.e. I always want to AI to take 3 seconds to make its decision on what move to make)

How can I do this in a pure language like Haskell? I expect that I'll need to do some diving into threads and such but I would prefer to minimize that as much as I can.

1 Answer

0 votes
by (97.2k points)

Since the result you're looking for depends on time, this is inevitably going to involve impure code.

It looks like System.Timeout from the base package provides the ability to run an I/O computation until some timeout. So all you need to do is write an IO computation that returns the result you're interested in. However, the tricky part is making the IO action actually compute the result, not just return an unevaluated result. For that, I think you need to evaluate from Control.Exception.

There is a small library based on those ideas that define a https://github.com/ppetr/timeout-with-resultsmonad for computations that can return partial results before returning the final one or dying on a timeout. See

If you wish to know more about Artificial Intelligence then visit this Artificial Intelligence Course.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !