Skip to content

Instantly share code, notes, and snippets.

@jaspervdj
Created December 6, 2019 11:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaspervdj/86a0179f44e083234d4c2377103a357a to your computer and use it in GitHub Desktop.
Save jaspervdj/86a0179f44e083234d4c2377103a357a to your computer and use it in GitHub Desktop.
Parser for readPrec
-- 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