{-
compile with:
$ stack install monad-par
$ stack --resolver lts-22.33 ghc -- --make -Wall -O partest.hs -threaded -rtsopts

to run in serial:
./partest - <depth>
to run in parallel:
./partest + <depth> +RTS -N<depth>

Note that you should still supply the same <depth> even if running in serial, since the total
amount of work done is based on the specified depth, even if only using one thread.

This is a test program I wrote to test out evaluating a list of values in parallel, which
is a strategy I will eventually use in my final program. It does nothing interesting,
but I used it to time parallel list operations.
-}

import System.Environment
import Control.Parallel.Strategies

testlist :: Int -> [Int]
testlist depth = do
  [x | a <- [0..depth], let x = foldr (+) (0 :: Int) (replicate ((100000000 :: Int) + a) (1 :: Int))]

main :: IO ()
main = do
  args <- getArgs
  case args of
    [p, depth] -> do
      let numdepth = read depth
      case p of
        "-" -> do
          let res = testlist numdepth
          putStrLn (show (foldr1 (\a b -> if a > b then a else b) res))
        "+" -> do
          let res = testlist numdepth `using` parList rseq
          putStrLn (show (foldr1 (\a b -> if a > b then a else b) res))
        _ -> putStrLn("usage error 2")
    _ -> putStrLn("usage error 1")
