Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Last active August 29, 2015 13:58
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save puffnfresh/10439989 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad.Trans (lift)
import Control.Parallel (par, pseq)
import Data.Text.Lazy (pack)
import System.Random (StdGen, newStdGen, random)
import Web.Scotty (get, scotty, text)
randomWalk :: Int -> Int -> StdGen -> Int
randomWalk s 0 _ = s
randomWalk s i r = randomWalk s' (pred i) g
where (b, g) = random r
s' = (if b then succ else pred) s
main :: IO ()
main = scotty 3000 $ do
a <- lift $ newStdGen
b <- lift $ newStdGen
get "/" $ do
let walk = randomWalk 0 10000000
first = walk a
second = walk b
text . pack . show $ first `par` second `pseq` (first + second)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment