Reputation: 11
I'm really new in Haskell. perhaps this is a simple question for the master coder. I want to remove the quotation mark outside the string. such as "A1" to A1.
I tried my best to solve this problem. but it doesn't work. I already used read :: Read a => String -> a, id function, and regular expression.
initialGuess :: ([Pitch],GameState)
initialGuess = (startGuess, GameState (chords))
where startGuess = ["A1", "B1", "C1"]
standard = [[n, o] | n <- ['A'..'G'], o <- ['1'..'3']] <br/>
chords = [[a,b,c] | a <- standard, b <- standard, c <-
standard, a /= b, b /= c, a /= c]
initialGuess aim to takes no input arguments.And returns a pair of an initial guess and a game state. Running this code I can get
["A1","B1","C1"],GameState [["A1","A2","A3"],["A1","A2","B1"],["A1","A2","B2"],["A1","A2","B3"],["A1","A2","C1"]................["A1","A2","C2"],["A1","A2","C3"],["A1","A2","D1"],["A1","A2","D2"],["A1","A2","D3"]]
however, I want to remove these quotation marks such as
[A1,B1,C1],GameState [[A1,A2,A3],[A1,A2,B1],[A1,A2,B2],[A1,A2,B3],[A1,A2,C1]................[A1,A2,C2],[A1,A2,C3],[A1,A2,D1],[A1,A2,D2],[A1,A2,D3]]
Upvotes: 1
Views: 357
Reputation: 8227
If all you are trying to do is make the states prettier, you can provide your own display function:
-- |Display a list of strings without quotation marks
showLStr :: [String] -> String
showLStr p = "[" ++ intercalate "," p ++ "]"
The intercalate
function puts the ","
between each element of the list of strings.
showLStr ["A1", "A2", "A3"]
should display as
[A1,A2,A3]
Edit: Now you can use showLStr
to display the game state:
showGameState :: GameState -> String
showGameState (GameState chords) =
"GameState [" ++ (intercalate "," $ map showLStr chords) ++ "]"
-- |Make GameState "Show"-able
instance Show GameState where
show = showGameState
showGuess :: ([Pitch],GameState) -> String
showGuess (pitch, gameState) = showLStr pitch ++ ", " ++ show gameState
Upvotes: 1