[Haskell-cafe] "Write Yourself a Scheme in 48 Hours"

Shannon -jj Behrens jjinux at gmail.com
Thu Feb 1 19:31:36 EST 2007


I'm going through the "Write Yourself a Scheme in 48 Hours"
<http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/overview.html>
tutorial.  I like it a lot, but I have some concerns.  Are the
exercises in the tutorial known to be solvable by mere mortals?

For instance:

"Rewrite parseNumber using...explicit sequencing with the >>= operator"
http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/parser.html#symbols

There aren't any examples of using >>= previous to this question.
Furthermore, the link to the Standard Prelude is not helpful because
there aren't any examples of how to use >>=.

Furthermore, consider the exercise:

"Change parseNumber to support the Scheme standard for different
bases. You may find the readOct and readHex functions useful."
http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/parser.html#symbols

I struggled against this for a couple hours last night.  How is the
reader supposed to figure out readOct, which is part of ReadS, without
understanding the whole ReadS business?  If the reader does understand
the ReadS business, he probably already understands Haskell far better
than the tutorial seems to suggest.  I eventually figured out how to
write:

parseHexNumber = do char '#'
                    char 'x'
                    s <- many1 (oneOf "0123456789abcdefABCDEF")
                    case readHex s of
                      [(n,"")] -> return n

but it was no small feat.  Furthermore, it was only possible because I
had already spent so much time trying to understand "A Gentle
Introduction to Haskell".  Worst of all, once I had it all
implemented, the parser *from* the tutorial:

parseExpr :: Parser LispVal
parseExpr = parseAtom
        <|> parseString
        <|> parseNumber

led to some surprising results.  It turns out that "#o9", which should be
an invalid attempt at an octal number, is getting parsed as an atom.
There's a whole layer of difficulty that seems insurmountable by mere
mortals like me using just this tutorial and minimal reference usage.

What am I missing?  Is it really solvable by mere mortals who don't
already know Haskell, the Parsec module, etc.?

Thanks,
-jj

-- 
http://jjinux.blogspot.com/


More information about the Haskell-Cafe mailing list