Home > Software engineering >  Problem with Chapter 2 of "Write Yourself a Scheme in 48 Hours"
Problem with Chapter 2 of "Write Yourself a Scheme in 48 Hours"

Time:11-23

I am trying to work through Write Yourself a Scheme in 48 Hours. But I am already running into problems on page 6.

The code provided is:

module Main where
import System.Environment
import Text.ParserCombinators.Parsec hiding ( spaces )

main :: IO ()
main = do 
    args <− getArgs
    putStrLn (readExpr ( args !! 0))

symbol :: Parser Char
symbol = oneOf "!$%&|* -/:<=?>@^_~#"

readExpr :: String −> String
readExpr input =  case parse symbol "lisp" input of
    Left err −> "No match: "    show err
    Right val −> "Found value"

when I run the following command

ghc -o parser simpleparser1.hs

the file is called simpleparser1.hs. I get the following error message. Which I find very strange considering that the code is from a classic book.

[1 of 1] Compiling Main             ( simpleparser1.hs, simpleparser1.o )

simpleparser1.hs:15:5: error:
    Parse error in pattern: Left err −> "No match: "    show err
   |
15 |     Left err −> "No match: "    show err
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I did look at this , this and this post on stackoverflow. I am a completely unfamiliar with Haskell so any help would be welcome.

CodePudding user response:

The PDF contains odd unicode symbols like which is not a normal dash, but rather a unicode "Minus Sign". To fix this simply replace them:

readExpr :: String -> String
readExpr input =  case parse symbol "lisp" input of
    Left err -> "No match: "    show err
    Right val -> "Found value"
  • Related