Created
December 6, 2019 11:56
-
-
Save jaspervdj/86a0179f44e083234d4c2377103a357a to your computer and use it in GitHub Desktop.
Parser for readPrec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Quick example of how to "properly" use readPrec with a "real" parser | |
import Data.Char (isDigit, toUpper) | |
import qualified Text.ParserCombinators.ReadP as P | |
import qualified Text.Read as R | |
data WirePath = WirePath {d :: Char, a :: Int} deriving (Show) | |
instance R.Read WirePath where | |
readPrec = R.readP_to_Prec $ const $ do | |
c <- P.get | |
s <- P.munch1 isDigit | |
return $ WirePath {d = toUpper c, a = read s} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment