From 286be2e4d951860fd9aa152dfe07f727c49963d6 Mon Sep 17 00:00:00 2001 From: krasimir Date: Sun, 19 Oct 2008 16:38:56 +0000 Subject: [PATCH] move PGF.Quiz to GF.Quiz. It is not part of the PGF API --- GF.cabal | 1 + src/GF/Command/Commands.hs | 2 +- src/GF/Infra/UseIO.hs | 28 ---------------------------- src/{PGF => GF}/Quiz.hs | 29 ++++++++++++++++++++++++++++- 4 files changed, 30 insertions(+), 30 deletions(-) rename src/{PGF => GF}/Quiz.hs (65%) diff --git a/GF.cabal b/GF.cabal index 10c08edd1..d9103679c 100644 --- a/GF.cabal +++ b/GF.cabal @@ -676,6 +676,7 @@ executable gf GF.Compile.GetGrammar GF.Compile GF.System.Readline + GF.Quiz PGF PGF.CId PGF.Data diff --git a/src/GF/Command/Commands.hs b/src/GF/Command/Commands.hs index 57303f53f..e9a2819ba 100644 --- a/src/GF/Command/Commands.hs +++ b/src/GF/Command/Commands.hs @@ -15,7 +15,6 @@ import PGF.ShowLinearize import PGF.Macros import PGF.Data ---- import PGF.Morphology -import PGF.Quiz import PGF.VisualizeTree import GF.Compile.Export import GF.Infra.Option (noOptions) @@ -26,6 +25,7 @@ import GF.Command.Abstract import GF.Command.Messages import GF.Text.Lexing import GF.Text.Transliterations +import GF.Quiz import GF.Command.TreeOperations ---- temporary place for typecheck and compute diff --git a/src/GF/Infra/UseIO.hs b/src/GF/Infra/UseIO.hs index 0ca8d7456..b4cf48f1f 100644 --- a/src/GF/Infra/UseIO.hs +++ b/src/GF/Infra/UseIO.hs @@ -153,34 +153,6 @@ putStrFlush s = putStr s >> hFlush stdout putStrLnFlush :: String -> IO () putStrLnFlush s = putStrLn s >> hFlush stdout --- * a generic quiz session - -type QuestionsAndAnswers = [(String, String -> (Integer,String))] - -teachDialogue :: QuestionsAndAnswers -> String -> IO () -teachDialogue qas welc = do - putStrLn $ welc ++++ genericTeachWelcome - teach (0,0) qas - where - teach _ [] = do putStrLn "Sorry, ran out of problems" - teach (score,total) ((question,grade):quas) = do - putStr ("\n" ++ question ++ "\n> ") - answer <- getLine - if (answer == ".") then return () else do - let (result, feedback) = grade answer - score' = score + result - total' = total + 1 - putStr (feedback ++++ "Score" +++ show score' ++ "/" ++ show total') - if (total' > 9 && fromInteger score' / fromInteger total' >= 0.75) - then do putStrLn "\nCongratulations - you passed!" - else teach (score',total') quas - - genericTeachWelcome = - "The quiz is over when you have done at least 10 examples" ++++ - "with at least 75 % success." +++++ - "You can interrupt the quiz by entering a line consisting of a dot ('.').\n" - - -- * IO monad with error; adapted from state monad newtype IOE a = IOE (IO (Err a)) diff --git a/src/PGF/Quiz.hs b/src/GF/Quiz.hs similarity index 65% rename from src/PGF/Quiz.hs rename to src/GF/Quiz.hs index 096930f46..92969aa3c 100644 --- a/src/PGF/Quiz.hs +++ b/src/GF/Quiz.hs @@ -12,7 +12,7 @@ -- translation and morphology quiz. AR 10\/5\/2000 -- 12\/4\/2002 -- 14\/6\/2008 -------------------------------------------------------------------------------- -module PGF.Quiz ( +module GF.Quiz ( mkQuiz, translationList, morphologyList @@ -69,3 +69,30 @@ mkAnswer cod as s = norml = unwords . words + +-- * a generic quiz session + +type QuestionsAndAnswers = [(String, String -> (Integer,String))] + +teachDialogue :: QuestionsAndAnswers -> String -> IO () +teachDialogue qas welc = do + putStrLn $ welc ++++ genericTeachWelcome + teach (0,0) qas + where + teach _ [] = do putStrLn "Sorry, ran out of problems" + teach (score,total) ((question,grade):quas) = do + putStr ("\n" ++ question ++ "\n> ") + answer <- getLine + if (answer == ".") then return () else do + let (result, feedback) = grade answer + score' = score + result + total' = total + 1 + putStr (feedback ++++ "Score" +++ show score' ++ "/" ++ show total') + if (total' > 9 && fromInteger score' / fromInteger total' >= 0.75) + then do putStrLn "\nCongratulations - you passed!" + else teach (score',total') quas + + genericTeachWelcome = + "The quiz is over when you have done at least 10 examples" ++++ + "with at least 75 % success." +++++ + "You can interrupt the quiz by entering a line consisting of a dot ('.').\n"