search :: String -> IO [HoogleResult]
search string = do
  response <- query string
  return $
    case response of
      Left err -> [NoResult err]
      Right json ->
        case eitherDecode $ LBS.fromStrict $ CBS.pack json of
          Left err -> [NoResult err]
          Right results ->
            case map SearchResult $ (\(HoogleResponseList l) -> l) results of
              []  -> [NoResult "no matching identifiers found."]
              res -> res

-- | Look up an identifier on Hoogle. Return documentation for that identifier. If there are many
-- identifiers, include documentation for all of them.
search :: String -> IO [HoogleResult]
search string = do
  response <- query string
  return $
    case response of
      Left err -> [NoResult err]
      Right json ->
        case eitherDecode $ LBS.fromStrict $ CBS.pack json of
          Left err -> [NoResult err]
          Right results ->
            case map SearchResult $ (\(HoogleResponseList l) -> l) results of
              []  -> [NoResult "no matching identifiers found."]
              res -> res

-- | Look up an identifier on Hoogle. Return documentation for that identifier. If there are many
-- identifiers, include documentation for all of them.
search string = do
  response <- query string
  return $
    case response of
      Left err -> [NoResult err]
      Right json ->
        case eitherDecode $ LBS.fromStrict $ CBS.pack json of
          Left err -> [NoResult err]
          Right results ->
            case map SearchResult $ (\(HoogleResponseList l) -> l) results of
              []  -> [NoResult "no matching identifiers found."]
              res -> res

-- | Look up an identifier on Hoogle. Return documentation for that identifier. If there are many
-- identifiers, include documentation for all of them.