Below is the code I have so far :
type Deck = [Card]
data Card = Card {question :: String, answer :: String} deriving (Show)
askForNextCommand deck = do
putStrLn "What would you like to do?"
userInput <- getLine
return userInput
loop :: Deck -> IO ()
loop deck = print $ askForNextCommand deck
main :: IO ()
main = loop []
The problem I'm having is with the askForNextCommand function. I'd like to be able to use the user input in another function like this :
There's a deck of cards, each of which contain a question and answer, and the user can be quizzed on them, add more cards to the list, remove cards, etc.
I've made a similar program in Python when I was learning it so I'm trying to make it in Haskell now.
I have another function that takes the input and does something with it depending on what the input is :
doCommand command deck
| command == "add" = addFunc deck
| command == "remove" = removeFunc deck
| otherwise = doCommand (askForNextCommand deck) deck
The problem is I can't figure out how to get the command parameter to be user input. I'd like askForNextCommand to prompt the user then return their input as a string, but I've been searching for about a half hour now and can't find anything. I'm sure it's an easy fix but I'm not sure where to look. Any help would be greatly appreciated.
fmap.addFunc/removeFunc?IO, my suggested change todoCommandwould be different than if it didn't.askForNextCommandsupposed to do? As it is written now, the argument toaskForNextCommandis totally unused...