How to run a Haskell program endlessly using only Haskell?

Filip van Hoft

I have small program that need to be executed every 5 minutes.

For now, I have shell script that perform that task, but I want to provide for user ability to run it without additional scripts via key in CLI.

What is the best way to achieve this?

Bartek Banachewicz

I presume you'll want something like that (more or less pseudocode):

import Control.Concurrent (forkIO, threadDelay)
import Data.IORef
import Control.Monad (forever)

main = do
    var <- newIORef 5000
    forkIO (forever $ process var)
    forever $ readInput var

process var = do
    doActualProcessing

    interval <- readIORef var
    _ <- threadDelay interval

readInput var = do
    newInterval <- readLn
    writeIORef var newInterval

If you need to pass some more complex data from the input thread to the processing thread, MVars or TVars could be a better choice than IORefs.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to program haskell with ghci?

From Dev

Using returned EitherT in haskell program

From Dev

How to run SAT calls in parallel using the picosat haskell bindings?

From Dev

How to run SAT calls in parallel using the picosat haskell bindings?

From Dev

How to write (<*>) using (=<<) in Haskell

From Dev

Using WinGHCi to implement first Haskell program

From Dev

How to find memory usage of a program in Haskell

From Dev

How to find memory usage of a program in Haskell

From Dev

How to make a Makefile for a program for Haskell Language?

From Dev

Run haskell gloss GUI using cabal

From Dev

How to run Haskell on OSX El Capitan

From Dev

Haskell program simple game

From Dev

Haskell - Result of a program

From Dev

Haskell program outputs `<<loop>>`

From Dev

Show progress of Haskell program

From Dev

Prime number program in haskell

From Dev

Show progress of Haskell program

From Dev

Memory leak in a haskell program

From Dev

Haskell optimization program

From Dev

Running a haskell program in ghci

From Dev

Converting a Prolog program to a Haskell program

From Dev

Haskell Hspec - only run expensive test on command line flag

From Dev

How to program in a type system that mismatches Haskell's System-Fw?

From Dev

How to write a Linux Top like console program in Haskell?

From Dev

How to make a Haskell program display a preliminary result in response to user input?

From Dev

How to write a zip file using Haskell LibZip?

From Dev

how to target haskell to android using jhc?

From Dev

How to sort a list using partial order in Haskell?

From Dev

How to write a zip file using Haskell LibZip?