parseProgram :: String -> Maybe Program
parseProgram str =
  case readP_to_S (do p <- program; eof; return p) str of
    [(p, "")] -> Just p
    []        -> Nothing
    parses    -> error $ foldr (.) id (showString "multiple parses:\n" : intersperse (showChar '\n') (map shows parses)) ""
parseProgram :: String -> Maybe Program
parseProgram str =
  case readP_to_S (do p <- program; eof; return p) str of
    [(p, "")] -> Just p
    []        -> Nothing
    parses    -> error $ foldr (.) id (showString "multiple parses:\n" : intersperse (showChar '\n') (map shows parses)) ""
parseProgram str =
  case readP_to_S (do p <- program; eof; return p) str of
    [(p, "")] -> Just p
    []        -> Nothing
    parses    -> error $ foldr (.) id (showString "multiple parses:\n" : intersperse (showChar '\n') (map shows parses)) ""