clanki 1.2.5 → 1.2.6
raw patch · 5 files changed
+26/−42 lines, 5 filesdep ~base
Dependency ranges changed: base
Files
- clanki.cabal +8/−2
- src/Add.hs +2/−5
- src/Card.hs +1/−1
- src/Display.hs +2/−2
- src/Quiz.hs +13/−32
clanki.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/ name: clanki-version: 1.2.5+version: 1.2.6 synopsis: Command-line spaced-repetition software description: Command-line spaced-repetition learning software. CL (command line) + Anki (popular spaced-repetition software) = Clanki. Usage is fairly simple, just follow the instructions after running the program. Add a deck, add cards to the deck, then quiz whenever possible. The program will determine what cards need to be reviewed, using the Super Memo 2 algorithm. license: MIT@@ -20,8 +20,14 @@ executable clanki main-is: Main.hs+ ghc-options: -Wall other-modules: Add, Quiz, Remove, Display, Card, Input, Tracker, StatTracker -- other-extensions: - build-depends: base >=4.6 && <4.8, time >= 1.4.2, directory >= 1.2.1.0, safe, bytestring, strict+ build-depends: base >=4.6 && < 4.9, + time >= 1.4.2, + directory >= 1.2.1.0, + safe, + bytestring, + strict hs-source-dirs: src default-language: Haskell2010
src/Add.hs view
@@ -39,9 +39,7 @@ toDeck cards = do chosenDeckName <- Input.getUserChoiceStr $ allDeckNames cards case chosenDeckName of- Just deckName -> do- newCards <- toDeckLoop deckName cards- return newCards+ Just deckName -> toDeckLoop deckName cards Nothing -> return cards @@ -56,8 +54,7 @@ _ -> do answer <- Input.sameLinePrompt "Add answer : " case answer of- "" -> do- return cards+ "" -> return cards _ -> do let card = newCard question answer deckName toDeckLoop deckName (card:cards)
src/Card.hs view
@@ -23,7 +23,7 @@ allDeckNames cards = nub . map cardDeck $ cards cardsInDeck :: String -> [Card] -> [Card]-cardsInDeck deckName cards = filter (\card -> cardDeck card == deckName) cards+cardsInDeck deckName = filter ((== deckName) . cardDeck) replaceCardsInDeck :: String -> [Card] -> [Card] -> [Card] replaceCardsInDeck deckName newCards allCards = do
src/Display.hs view
@@ -5,6 +5,6 @@ class (Show a) => Display a where display :: a -> String -displayList list = do- printf . (++ "\n") . intercalate "\n" . map (("-" ++) . display) $ list+displayList :: Display a => [a] -> IO ()+displayList list = printf . (++ "\n") . intercalate "\n" . map (("-" ++) . display) $ list
src/Quiz.hs view
@@ -8,10 +8,9 @@ import Data.Time.Clock.POSIX import Data.Maybe(isJust) import qualified Input-import Control.Monad(filterM)+import Control.Monad(filterM, liftM) import System.IO(hSetBuffering, BufferMode(NoBuffering, LineBuffering), stdin, stdout, hFlush) import Data.List((\\), isInfixOf, delete)-{-import StatTracker-} data QuizAction = AllCards | FromDeck deriving (Show, Eq) allQuizActions :: [QuizAction]@@ -27,29 +26,20 @@ runQuizAction quizAction cards anyCardsToQuiz :: [Card] -> IO Bool-anyCardsToQuiz cards = shouldQuizList >>= return . (True `elem`)- where shouldQuizList = sequence [shouldQuizCard card | card <- cards] +anyCardsToQuiz cards = liftM (True `elem`) shouldQuizList+ where shouldQuizList = sequence $ fmap shouldQuizCard cards runQuizAction :: Maybe QuizAction -> [Card] -> IO [Card] runQuizAction (Just AllCards) cards = cardsToQuiz cards >>= (\someCards -> quizSomeCards someCards cards) runQuizAction (Just FromDeck) cards = do input <- Input.getUserChoiceStr $ allDeckNames cards case input of- Just deckName -> do- quizFromDeck deckName cards+ Just deckName -> quizFromDeck deckName cards Nothing -> return cards runQuizAction Nothing decks = return decks -{-quizCards :: [Card] -> IO [Card]-}-{-quizCards cards = do-}- {-newCards <- sequence [maybeQuiz card | card <- cards]-}- {-return cards-}--{-maybeQuiz :: Card -> IO Card-}-{-maybeQuiz card = shouldQuizCard card >>= (\shouldQuiz -> if shouldQuiz then quizCard card else return card)-}- cardsToQuiz :: [Card] -> IO [Card]-cardsToQuiz cards = filterM shouldQuizCard cards+cardsToQuiz = filterM shouldQuizCard quizCards :: [Card] -> IO [Card] quizCards [] = return []@@ -69,11 +59,10 @@ Just updatedCard -> do needsRequizzing <- shouldQuizCard updatedCard if needsRequizzing- then do- quizSomeCards' (restOfCards ++ [updatedCard]) allCards+ then quizSomeCards' (restOfCards ++ [updatedCard]) allCards else do let newAllCards = (updatedCard:) . delete headCard $ allCards - quizSomeCards' (restOfCards) newAllCards+ quizSomeCards' restOfCards newAllCards where headCard = head cards restOfCards = tail cards@@ -81,9 +70,6 @@ quizCard :: Card -> IO (Maybe Card) quizCard card = do printf $ "Question : " ++ cardQuestion card ++ "\n"- {-printf $ "Answer : "-}- {-hFlush stdout-}- {-answer <- getLine-} answer <- Input.sameLinePrompt "Answer : " confidence <- getConfidence answer (cardAnswer card) case confidence of@@ -101,25 +87,21 @@ getConfidence :: String -> String -> IO (Maybe Int) getConfidence answer correctAnswer- | isJust inferredConfidence = return $ inferredConfidence+ | isJust inferredConfidence = return inferredConfidence | otherwise = do printf $ "Correct answer : " ++ correctAnswer ++ "\n"- printf $ "Rate your answer on a scale from 0-5 : "+ printf "Rate your answer on a scale from 0-5 : " hFlush stdout promptConfidence where inferredConfidence = inferConfidence answer correctAnswer +{- Default values to use when the user is right, not yet implemented -} inferConfidence :: String -> String -> Maybe Int inferConfidence answer correctAnswer- | rightAnswer =- case answer \\ correctAnswer of- {-"!" -> Just 5-}- {-"." -> Just 4-}- {-"?" -> Just 3-}- _ -> Nothing+ | rightAnswer = Nothing | otherwise = Nothing- where rightAnswer = correctAnswer `isInfixOf` answer+ where rightAnswer = correctAnswer == answer promptConfidence :: IO (Maybe Int) promptConfidence = do@@ -150,8 +132,7 @@ [] -> do printf $ "No cards need to be quizzed at this time" ++ "\n" return Nothing- _ -> do- case allDeckNames cards of+ _ -> case allDeckNames cards of [_] -> return $ Just AllCards _ -> do printf $ "What would you like to be quizzed on?" ++ "\n"