読者です 読者をやめる 読者になる 読者になる

ふつけるでMaybeモナド中

Haskell
config :: [(String, [(String, String)])];
config =
  [ ("database",  [("path", "var/app/db"), ("encoding", "euc-jp")]),
    ("urlmapper", [("cgiurl", "/app"), ("rewrite", "True")]),
    ("template",  [("path", "/var/app/template")]) ]
main = print $ case (lookup "database" config) of
                 Just entries -> lookup "encoding" entries
                 Nothing      -> Nothing

main = print $ lookup "database" config >>= lookup "encoding"

main = print $ return config >>= lookup "database" >>= lookup "encoding"