-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Description
This refers to PR #59.
- The standard prelude does not include
readMaybe.Text.Readneeds to be imported. - The type annotation was insufficient. I needed to add
Read ato theNothingcase. - These two issues make it seem too complicated for inclusion in a beginner's text.
It should be revised or deleted ("feature creep" is the problem).
This code compiles:
densityTell :: String -> String
densityTell input
| Just density <- readMaybe input, density < 1.2 = "Wow! You're going for a ride in the sky!"
| Just density <- readMaybe input, density <= 1000.0 = "Have fun swimming, but watch out for sharks!"
| Nothing <- readMaybe input :: ((Read a, RealFloat a) => Maybe a) = "You know I need a density, right?"
| otherwise = "If it's sink or swim, you're going to sink."Suggested revision (to be completed by me someday). I actually think this is ugly (and bad style), and the topic should be removed, but this (relatively cleanly) fixes the issue I noted.
densityRead:: String -> Maybe Double
densityRead input = readMaybe input
densityTell' :: String -> String
densityTell' input
| Just density <- result, density < 1.2 = "Wow! You're going for a ride in the sky!"
| Just density <- result, density < 1000.0 = "Have fun swimming, but watch out for sharks!"
| Nothing <- result = "You know I need a density, right?"
| otherwise = "If it's sink or swim, you're going to sink."
where result = densityRead inputstonega, Stef9998 and kyusu
Metadata
Metadata
Assignees
Labels
No labels