I want to read from a file in a game I'm making in Haskell using Gloss. The file is in JSON format, and the JSON is correctly loaded, but then it seems to get removed or something. In the code below, putStr (show highScores2)
is ignored, and so are both of the putStr
in the cases in the second code segment.
Why isn't the code in the cases executed, does this have to do with lazy evalutation? (or is it executed?) I don't see how, since this code is necessary for the remainder of the program.
My JSON:
[{"score":345,"date":"timeString"}]
My code:
main :: IO ()
main = do
gen <- getStdGen
highScores <- loadHighScores
let highScores2 = highScores ++ [Entry 895 "testingtesting"]
putStr (show highScores2)
playIO
FullScreen -- Fullscreen
black -- Background color
60 -- Frames per second
(initialState gen highScores2) -- Initial state
view -- View function
input -- Event function
step -- Step function
File handling code, in this segment B.putStr json
does print something to the screen, so I know it reads the JSON, but both the putStr
s are ignored in the case segment:
loadHighScores :: IO [HighScoreEntry]
loadHighScores = do
json <- B.readFile highScorePath --Does not check for file does not exist
B.putStr json
-- let d = eitherDecode json :: Either String [HighScoreEntry]
-- case d of
-- Left err -> return []
-- Right hS -> putStr "EUI" >> return hS
let d = decode json
case d of
Just hS -> (putStr $ "second - " ++ show hS) >> return hS
otherwise -> (putStr "whyyy") >> return []
Output:
[{"score":345,"date":"timeString"}]