Created
August 20, 2014 19:30
-
-
Save rntz/6eda3532ee7b6cfb4507 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Control.Monad (mapM_) | |
import Data.List (intersperse) | |
import System.CPUTime | |
import Text.Printf | |
import qualified Data.Set as Set | |
import Text.Derp | |
time :: IO t -> IO t | |
time a = do start <- getCPUTime | |
v <- a | |
end <- getCPUTime | |
let diff :: Double | |
diff = (fromIntegral (end - start)) / (10 ** 12) | |
printf "Computation time: %0.3f sec\n" (diff :: Double) | |
return v | |
-- amb is the grammar we want, namely russ cox's | |
-- S = S + S | 1 | |
testOk :: Int -> [Token String] | |
testOk n = intersperse (Token "+" "+") (replicate n (Token "1" "1")) | |
runOk :: Int -> Set.Set String | |
runOk n = runParse (amb ()) (testOk n) | |
test n = parser `seq` -- don't count time to construct parser | |
length input `seq` -- or input | |
time $ do let parses = runParse parser input | |
let first = head (Set.toList parses) | |
printf "on input of length %d first parse is: %s...\n" | |
n (take 10 first) | |
where parser = amb () | |
input = testOk n | |
main = mapM_ test [1..14] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment