What goes through?

In code:

oneChar :: Char -> Doc
oneChar c = case lookup c simpleEscapes of
              Just r -> text r
              Nothing | mustEscape c -> hexEscape c
                       | otherwise   -> char c
    where mustEscape c = c < ' ' || c == '\x7f' || c > '\xff'

simpleEscapes :: [(Char, String)]
simpleEscapes = zipWith ch "\b\n\f\r\t\\\"/" "bnfrt\\\"/"
    where ch a b = (a, ['\\',b])

r is not passed to oneChar. Where does r come from?

+5
source share
4 answers

lookup c simpleEscapesreturns a value Maybe Stringthat can be either Nothingor Just <a string>. ris the string contained in Just, as defined in the string:

Just r -> text r
+5
source

case , case EXPR of (PATTERN -> EXPR)+. , Just r - , lookup c simpleEscapes of. . , lookup c simpleEscapes of a Just, r Just, text r.

+3

, , case , c .

:

(\(Just x) -> x) foo

let (Just x) = foo in x

f (Just x) = x

case foo of 
    Just x -> x

... x. , , case .

+2

You use the case statement for the value returned by a search with simpleEscapes, which is of type Maybe. Maybe there are two data constructors: Just and Nothing. The Just data constructor is processed with a single value, the Nothing constructor has nothing.

So, in this case, r is a formal parameter for the Just data constructor: its actual value in the return value from the search.

+1
source

All Articles