    {-# LANGUAGE PatternGuards, ViewPatterns, RecordWildCards #-}
    {-# LANGUAGE OverloadedStrings #-}
    {-# OPTIONS_GHC -O0 #-} -- otherwise it takes a lot of memory to compile on the haskell.org server

    module Query(
        Query(..), isQueryName, isQueryType, isQueryScope,
        parseQuery, renderQuery,
        query_test
        ) where

    import Data.List
    import Language.Haskell.Exts
    import Data.Char
    import Text.Blaze
    import qualified Text.Blaze.XHtml5 as H
    import Data.List.Extra
    import Data.Generics.Uniplate.Data
    import General.Util
    import Data.Maybe
    import Data.Monoid
    import Control.Applicative
    import Prelude

    ---------------------------------------------------------------------
    -- DATA TYPE

    data Query
        = QueryName {Query -> String
    fromQueryName :: String}
        | QueryType {Query -> Type ()
    fromQueryType :: Type ()}
        | QueryScope {Query -> Bool
    scopeInclude :: Bool, Query -> String
    scopeCategory :: String, Query -> String
    scopeValue :: String}
        | QueryNone String -- part of the query that is ignored
          deriving (Int -> Query -> ShowS
    [Query] -> ShowS
    Query -> String
    (Int -> Query -> ShowS)
    -> (Query -> String) -> ([Query] -> ShowS) -> Show Query
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Query -> ShowS
    showsPrec :: Int -> Query -> ShowS
    $cshow :: Query -> String
    show :: Query -> String
    $cshowList :: [Query] -> ShowS
    showList :: [Query] -> ShowS
    Show,Query -> Query -> Bool
    (Query -> Query -> Bool) -> (Query -> Query -> Bool) -> Eq Query
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Query -> Query -> Bool
    == :: Query -> Query -> Bool
    $c/= :: Query -> Query -> Bool
    /= :: Query -> Query -> Bool
    Eq)

    isQueryName, isQueryType, isQueryScope :: Query -> Bool
    isQueryName :: Query -> Bool
    isQueryName QueryName{} = Bool
    True; isQueryName Query
    _ = Bool
    False
    isQueryType :: Query -> Bool
    isQueryType QueryType{} = Bool
    True; isQueryType Query
    _ = Bool
    False
    isQueryScope :: Query -> Bool
    isQueryScope QueryScope{} = Bool
    True; isQueryScope Query
    _ = Bool
    False

    renderQuery :: [Query] -> Markup
    renderQuery :: [Query] -> Html
    renderQuery [] = Html -> Html
    H.i Html
    "No query"
    renderQuery [Query]
    xs = do
        String -> Html
    string (String -> Html) -> String -> Html
    forall a b. (a -> b) -> a -> b
    $ [String] -> String
    unwords ([String] -> String) -> [String] -> String
    forall a b. (a -> b) -> a -> b
    $
            [String
    x | QueryName String
    x <- [Query]
    xs] [String] -> [String] -> [String]
    forall a. [a] -> [a] -> [a]
    ++
            [String
    ":: " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ Type () -> String
    forall a. Pretty a => a -> String
    pretty Type ()
    x | QueryType Type ()
    x <- [Query]
    xs] [String] -> [String] -> [String]
    forall a. [a] -> [a] -> [a]
    ++
            [[Char
    '-' | Bool -> Bool
    not Bool
    scopeInclude] String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    scopeCategory String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    ":" String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    scopeValue | QueryScope{Bool
    String
    scopeInclude :: Query -> Bool
    scopeCategory :: Query -> String
    scopeValue :: Query -> String
    scopeInclude :: Bool
    scopeCategory :: String
    scopeValue :: String
    ..} <- [Query]
    xs]
        [Html] -> Html
    forall a. Monoid a => [a] -> a
    mconcat [Html
    " " Html -> Html -> Html
    forall a. Semigroup a => a -> a -> a
    <> Html -> Html
    H.del (String -> Html
    string String
    x) | QueryNone String
    x <- [Query]
    xs]

    ---------------------------------------------------------------------
    -- PARSER

    parseQuery :: String -> [Query]
    parseQuery :: String -> [Query]
    parseQuery String
    x = (String -> Query) -> [String] -> [Query]
    forall a b. (a -> b) -> [a] -> [b]
    map String -> Query
    QueryName [String]
    nam [Query] -> [Query] -> [Query]
    forall a. [a] -> [a] -> [a]
    ++ (Type () -> Query) -> [Type ()] -> [Query]
    forall a b. (a -> b) -> [a] -> [b]
    map Type () -> Query
    QueryType (Maybe (Type ()) -> [Type ()]
    forall a. Maybe a -> [a]
    maybeToList Maybe (Type ())
    typ) [Query] -> [Query] -> [Query]
    forall a. [a] -> [a] -> [a]
    ++ [Query]
    scp
        where
            ([Query]
    scp,[String]
    rest) = [String] -> ([Query], [String])
    scope_ ([String] -> ([Query], [String]))
    -> [String] -> ([Query], [String])
    forall a b. (a -> b) -> a -> b
    $ String -> [String]
    lexer String
    x
            ([String]
    nam,Maybe (Type ())
    typ) = [String] -> ([String], Maybe (Type ()))
    divide [String]
    rest

    openBrackets :: [String]
    openBrackets = [String
    "(#",String
    "[:",String
    "(",String
    "["]
    shutBrackets :: [String]
    shutBrackets = [String
    "#)",String
    ":]",String
    ")",String
    "]"]

    isBracket :: String -> Bool
    isBracket String
    x = String
    x String -> [String] -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` ([String]
    openBrackets [String] -> [String] -> [String]
    forall a. [a] -> [a] -> [a]
    ++ [String]
    shutBrackets)
    isBracketPair :: String -> Bool
    isBracketPair String
    x = String
    x String -> [String] -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` (String -> ShowS) -> [String] -> [String] -> [String]
    forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
    zipWith String -> ShowS
    forall a. [a] -> [a] -> [a]
    (++) [String]
    openBrackets [String]
    shutBrackets

    isSym :: Char -> Bool
    isSym Char
    x = ((Char -> Bool
    isSymbol Char
    x Bool -> Bool -> Bool
    || Char -> Bool
    isPunctuation Char
    x) Bool -> Bool -> Bool
    && Char
    x Char -> String -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `notElem` String
    special) Bool -> Bool -> Bool
    || Char
    x Char -> String -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` String
    ascSymbol
        where special :: String
    special = String
    "(),;[]`{}\"'" :: String
              ascSymbol :: String
    ascSymbol = String
    "!#$%&*+./<=>?@\\^|-~" :: String

    isSyms :: String -> Bool
    isSyms String
    xs | String -> Bool
    isBracket String
    xs Bool -> Bool -> Bool
    || String -> Bool
    isBracketPair String
    xs = Bool
    False
    isSyms (Char
    x:String
    xs) = Char -> Bool
    isSym Char
    x
    isSyms [] = Bool
    False

    -- | Split into small lexical chunks.
    --
    -- > "Data.Map.(!)" ==> ["Data",".","Map",".","(","!",")"]
    lexer :: String -> [String]
    lexer :: String -> [String]
    lexer (Char
    '(':Char
    ',':String
    xs) | (String
    a,Char
    ')':String
    b) <- (Char -> Bool) -> String -> (String, String)
    forall a. (a -> Bool) -> [a] -> ([a], [a])
    span (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == Char
    ',') String
    xs = (String
    "(," String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    a String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    ")") String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    : String -> [String]
    lexer String
    b
    lexer String
    x | Just String
    s <- ([String]
    bs [String] -> Int -> String
    forall a. HasCallStack => [a] -> Int -> a
    !!) (Int -> String) -> Maybe Int -> Maybe String
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (String -> Bool) -> [String] -> Maybe Int
    forall a. (a -> Bool) -> [a] -> Maybe Int
    findIndex (String -> String -> Bool
    forall a. Eq a => [a] -> [a] -> Bool
    `isPrefixOf` String
    x) [String]
    bs = String
    s String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    : String -> [String]
    lexer (Int -> ShowS
    forall a. Int -> [a] -> [a]
    drop (String -> Int
    forall a. [a] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length String
    s) String
    x)
        where bs :: [String]
    bs = (String -> ShowS) -> [String] -> [String] -> [String]
    forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
    zipWith String -> ShowS
    forall a. [a] -> [a] -> [a]
    (++) [String]
    openBrackets [String]
    shutBrackets [String] -> [String] -> [String]
    forall a. [a] -> [a] -> [a]
    ++ [String]
    openBrackets [String] -> [String] -> [String]
    forall a. [a] -> [a] -> [a]
    ++ [String]
    shutBrackets
    lexer (Char
    x:String
    xs)
        | Char -> Bool
    isSpace Char
    x = String
    " " String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    : String -> [String]
    lexer (ShowS
    trimStart String
    xs)
        | Char -> Bool
    isAlpha Char
    x Bool -> Bool -> Bool
    || Char
    x Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == Char
    '_' =
            let (String
    a,String
    b) = (Char -> Bool) -> String -> (String, String)
    forall a. (a -> Bool) -> [a] -> ([a], [a])
    span (\Char
    x -> Char -> Bool
    isAlphaNum Char
    x Bool -> Bool -> Bool
    || Char
    x Char -> String -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` (String
    "_'#-" :: String)) String
    xs
                (String
    a1,String
    a2) = (Char -> Bool) -> String -> (String, String)
    forall a. (a -> Bool) -> [a] -> ([a], [a])
    spanEnd (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == Char
    '-') String
    a
            in (Char
    xChar -> ShowS
    forall a. a -> [a] -> [a]
    :String
    a1) String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    : String -> [String]
    lexer (String
    a2 String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    b)
        | Char -> Bool
    isSym Char
    x = let (String
    a,String
    b) = (Char -> Bool) -> String -> (String, String)
    forall a. (a -> Bool) -> [a] -> ([a], [a])
    span Char -> Bool
    isSym String
    xs in (Char
    xChar -> ShowS
    forall a. a -> [a] -> [a]
    :String
    a) String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    : String -> [String]
    lexer String
    b
        | Char
    x Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == Char
    ',' = String
    "," String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    : String -> [String]
    lexer String
    xs
        | Bool
    otherwise = String -> [String]
    lexer String
    xs -- drop invalid bits
    lexer [] = []

    -- | Find and extract the scope annotations.
    --
    -- > +package
    -- > +module
    -- > name.bar
    -- > name.++ name.(++) (name.++)
    -- > +foo -foo
    -- > +scope:foo -scope:foo scope:foo
    scope_ :: [String] -> ([Query], [String])
    scope_ :: [String] -> ([Query], [String])
    scope_ [String]
    xs = case [String]
    xs of
        (String -> Maybe Bool
    forall {a}. (Eq a, IsString a) => a -> Maybe Bool
    readPM -> Just Bool
    pm):(String -> Maybe String
    readCat -> Just String
    cat):String
    ":":([String] -> Maybe (String, [String])
    readMod -> Just (String
    mod,[String]
    rest)) -> Bool -> String -> String -> [String] -> ([Query], [String])
    add Bool
    pm String
    cat String
    mod [String]
    rest
        (String -> Maybe Bool
    forall {a}. (Eq a, IsString a) => a -> Maybe Bool
    readPM -> Just Bool
    pm):(String -> Maybe String
    readCat -> Just String
    cat):String
    ":-":([String] -> Maybe (String, [String])
    readMod -> Just (String
    mod,[String]
    rest)) -> Bool -> String -> String -> [String] -> ([Query], [String])
    add Bool
    False String
    cat String
    mod [String]
    rest
        (String -> Maybe Bool
    forall {a}. (Eq a, IsString a) => a -> Maybe Bool
    readPM -> Just Bool
    pm):([String] -> Maybe (String, [String])
    readMod -> Just (String
    mod,[String]
    rest)) -> Bool -> String -> [String] -> ([Query], [String])
    add_ Bool
    pm String
    mod [String]
    rest
        (String -> Maybe String
    readCat -> Just String
    cat):String
    ":":([String] -> Maybe (String, [String])
    readMod -> Just (String
    mod,[String]
    rest)) -> Bool -> String -> String -> [String] -> ([Query], [String])
    add Bool
    True String
    cat String
    mod [String]
    rest
        (String -> Maybe String
    readCat -> Just String
    cat):String
    ":.":([String] -> Maybe (String, [String])
    readMod -> Just (String
    mod,[String]
    rest)) -> Bool -> String -> String -> [String] -> ([Query], [String])
    add Bool
    True String
    cat (Char
    '.'Char -> ShowS
    forall a. a -> [a] -> [a]
    :String
    mod) [String]
    rest
        (String -> Maybe String
    readCat -> Just String
    cat):String
    ":-":([String] -> Maybe (String, [String])
    readMod -> Just (String
    mod,[String]
    rest)) -> Bool -> String -> String -> [String] -> ([Query], [String])
    add Bool
    False String
    cat String
    mod [String]
    rest
        (String -> Maybe String
    readCat -> Just String
    cat):String
    ":-.":([String] -> Maybe (String, [String])
    readMod -> Just (String
    mod,[String]
    rest)) -> Bool -> String -> String -> [String] -> ([Query], [String])
    add Bool
    False String
    cat (Char
    '.'Char -> ShowS
    forall a. a -> [a] -> [a]
    :String
    mod) [String]
    rest
        String
    "(":([String] -> Maybe (String, [String])
    readDots -> Just (String
    scp,String
    x:String
    ")":[String]
    rest)) -> [String] -> ([Query], [String]) -> ([Query], [String])
    forall {a} {a}. [a] -> (a, [a]) -> (a, [a])
    out [String
    "(",String
    x,String
    ")"] (([Query], [String]) -> ([Query], [String]))
    -> ([Query], [String]) -> ([Query], [String])
    forall a b. (a -> b) -> a -> b
    $ Bool -> String -> [String] -> ([Query], [String])
    add_ Bool
    True String
    scp [String]
    rest
        ([String] -> Maybe (String, [String])
    readDots -> Just (String
    scp,[String]
    rest)) -> Bool -> String -> [String] -> ([Query], [String])
    add_ Bool
    True String
    scp [String]
    rest
        String
    "(":String
    ".":([String] -> Maybe (String, [String])
    readDots -> Just (String
    scp,String
    x:String
    ")":[String]
    rest)) -> [String] -> ([Query], [String]) -> ([Query], [String])
    forall {a} {a}. [a] -> (a, [a]) -> (a, [a])
    out [String
    "(",String
    x,String
    ")"] (([Query], [String]) -> ([Query], [String]))
    -> ([Query], [String]) -> ([Query], [String])
    forall a b. (a -> b) -> a -> b
    $ Bool -> String -> [String] -> ([Query], [String])
    add_ Bool
    True (Char
    '.'Char -> ShowS
    forall a. a -> [a] -> [a]
    :String
    scp) [String]
    rest
        String
    ".":([String] -> Maybe (String, [String])
    readDots -> Just (String
    scp,[String]
    rest)) -> Bool -> String -> [String] -> ([Query], [String])
    add_ Bool
    True (Char
    '.'Char -> ShowS
    forall a. a -> [a] -> [a]
    :String
    scp) [String]
    rest
        String
    x:[String]
    xs -> [String] -> ([Query], [String]) -> ([Query], [String])
    forall {a} {a}. [a] -> (a, [a]) -> (a, [a])
    out [String
    x] (([Query], [String]) -> ([Query], [String]))
    -> ([Query], [String]) -> ([Query], [String])
    forall a b. (a -> b) -> a -> b
    $ [String] -> ([Query], [String])
    scope_ [String]
    xs
        [] -> ([], [])
        where
            out :: [a] -> (a, [a]) -> (a, [a])
    out [a]
    xs (a
    a,[a]
    b) = (a
    a,[a]
    xs[a] -> [a] -> [a]
    forall a. [a] -> [a] -> [a]
    ++[a]
    b)
            add :: Bool -> String -> String -> [String] -> ([Query], [String])
    add Bool
    a String
    b String
    c [String]
    rest = let ([Query]
    x,[String]
    y) = [String] -> ([Query], [String])
    scope_ [String]
    rest in (Bool -> String -> String -> Query
    QueryScope Bool
    a String
    b String
    c Query -> [Query] -> [Query]
    forall a. a -> [a] -> [a]
    : [Query]
    x, [String]
    y)
            add_ :: Bool -> String -> [String] -> ([Query], [String])
    add_ Bool
    a String
    c [String]
    rest = Bool -> String -> String -> [String] -> ([Query], [String])
    add Bool
    a String
    b String
    c [String]
    rest
                where b :: String
    b = if Char
    '.' Char -> String -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` String
    c Bool -> Bool -> Bool
    || (Char -> Bool) -> String -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    any Char -> Bool
    isUpper (Int -> ShowS
    forall a. Int -> [a] -> [a]
    take Int
    1 String
    c) then String
    "module" else String
    "package"

            readPM :: a -> Maybe Bool
    readPM a
    x = case a
    x of a
    "+" -> Bool -> Maybe Bool
    forall a. a -> Maybe a
    Just Bool
    True; a
    "-" -> Bool -> Maybe Bool
    forall a. a -> Maybe a
    Just Bool
    False; a
    _ -> Maybe Bool
    forall a. Maybe a
    Nothing

            readCat :: String -> Maybe String
    readCat String
    x | String -> Bool
    isAlpha1 String
    x = String -> Maybe String
    forall a. a -> Maybe a
    Just String
    x
                      | Bool
    otherwise = Maybe String
    forall a. Maybe a
    Nothing

            readMod :: [String] -> Maybe (String, [String])
    readMod (String
    x:[String]
    xs) | String -> Bool
    isAlpha1 String
    x = (String, [String]) -> Maybe (String, [String])
    forall a. a -> Maybe a
    Just ((String, [String]) -> Maybe (String, [String]))
    -> (String, [String]) -> Maybe (String, [String])
    forall a b. (a -> b) -> a -> b
    $ case [String]
    xs of
                String
    ".":[String]
    ys | Just (String
    a,[String]
    b) <- [String] -> Maybe (String, [String])
    readMod [String]
    ys -> (String
    x String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    "." String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    a, [String]
    b)
                String
    ".":[] -> (String
    x String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    ".",[])
                String
    ".":String
    " ":[String]
    ys -> (String
    x String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    ".",String
    " "String -> [String] -> [String]
    forall a. a -> [a] -> [a]
    :[String]
    ys)
                [String]
    _ -> (String
    x,[String]
    xs)
            readMod [String]
    _ = Maybe (String, [String])
    forall a. Maybe a
    Nothing

            readDots :: [String] -> Maybe (String, [String])
    readDots (String
    x:[String]
    xs) | String -> Bool
    isAlpha1 String
    x = case [String]
    xs of
                String
    ".":[String]
    ys | Just (String
    a,[String]
    b) <- [String] -> Maybe (String, [String])
    readDots [String]
    ys -> (String, [String]) -> Maybe (String, [String])
    forall a. a -> Maybe a
    Just (String
    x String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    "." String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    a, [String]
    b)
                (Char
    '.':String
    y):[String]
    ys -> (String, [String]) -> Maybe (String, [String])
    forall a. a -> Maybe a
    Just (String
    x, [String
    y | String
    y String -> String -> Bool
    forall a. Eq a => a -> a -> Bool
    /= String
    ""] [String] -> [String] -> [String]
    forall a. [a] -> [a] -> [a]
    ++ [String]
    ys)
                [String]
    _ -> Maybe (String, [String])
    forall a. Maybe a
    Nothing
            readDots [String]
    _ = Maybe (String, [String])
    forall a. Maybe a
    Nothing

    -- | If everything is a name, or everything is a symbol, then you only have names.
    divide :: [String] -> ([String], Maybe (Type ()))
    divide :: [String] -> ([String], Maybe (Type ()))
    divide [String]
    xs | (String -> Bool) -> [String] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    all String -> Bool
    isAlpha1 [String]
    ns = ([String]
    ns, Maybe (Type ())
    forall a. Maybe a
    Nothing)
              | (String -> Bool) -> [String] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    all String -> Bool
    isSyms [String]
    ns = ([String]
    ns, Maybe (Type ())
    forall a. Maybe a
    Nothing)
              | [String] -> Int
    forall a. [a] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [String]
    ns Int -> Int -> Bool
    forall a. Eq a => a -> a -> Bool
    == Int
    1 = ([String]
    ns, Maybe (Type ())
    forall a. Maybe a
    Nothing)
              | Bool
    otherwise = case (String -> Bool) -> [String] -> ([String], [String])
    forall a. (a -> Bool) -> [a] -> ([a], [a])
    break (String -> String -> Bool
    forall a. Eq a => a -> a -> Bool
    == String
    "::") [String]
    xs of
                    ([String]
    nam, String
    _:[String]
    rest) -> ([String] -> [String]
    names_ [String]
    nam, [String] -> Maybe (Type ())
    typeSig_ [String]
    rest)
                    ([String], [String])
    _ -> ([], [String] -> Maybe (Type ())
    typeSig_ [String]
    xs)
        where ns :: [String]
    ns = [String] -> [String]
    names_ [String]
    xs

    -- | Ignore brackets around symbols, and try to deal with tuple names.
    names_ :: [String] -> [String]
    names_ :: [String] -> [String]
    names_ (String
    "(":String
    x:String
    ")":[String]
    xs) = [String
    x | String
    x String -> String -> Bool
    forall a. Eq a => a -> a -> Bool
    /= String
    " "] [String] -> [String] -> [String]
    forall a. [a] -> [a] -> [a]
    ++ [String] -> [String]
    names_ [String]
    xs
    names_ [String
    "(",String
    x] = [String
    x]
    names_ (String
    x:[String]
    xs) = [String
    x | String
    x String -> String -> Bool
    forall a. Eq a => a -> a -> Bool
    /= String
    " "] [String] -> [String] -> [String]
    forall a. [a] -> [a] -> [a]
    ++ [String] -> [String]
    names_ [String]
    xs
    names_ [] = []

    typeSig_ :: [String] -> Maybe (Type ())
    typeSig_ :: [String] -> Maybe (Type ())
    typeSig_ [String]
    xs = case ParseMode -> String -> ParseResult (Type SrcSpanInfo)
    parseTypeWithMode ParseMode
    parseMode (String -> ParseResult (Type SrcSpanInfo))
    -> String -> ParseResult (Type SrcSpanInfo)
    forall a b. (a -> b) -> a -> b
    $ [String] -> String
    unwords ([String] -> String) -> [String] -> String
    forall a b. (a -> b) -> a -> b
    $ [String] -> [String]
    fixup ([String] -> [String]) -> [String] -> [String]
    forall a b. (a -> b) -> a -> b
    $ (String -> Bool) -> [String] -> [String]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (Bool -> Bool
    not (Bool -> Bool) -> (String -> Bool) -> String -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char -> Bool) -> String -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    all Char -> Bool
    isSpace) [String]
    xs of
        ParseOk Type SrcSpanInfo
    x -> Type () -> Maybe (Type ())
    forall a. a -> Maybe a
    Just (Type () -> Maybe (Type ())) -> Type () -> Maybe (Type ())
    forall a b. (a -> b) -> a -> b
    $ (Name () -> Name ()) -> Type () -> Type ()
    forall from to. Biplate from to => (to -> to) -> from -> from
    transformBi (\Name ()
    v -> if Name ()
    v Name () -> Name () -> Bool
    forall a. Eq a => a -> a -> Bool
    == () -> String -> Name ()
    forall l. l -> String -> Name l
    Ident () String
    "__" then () -> String -> Name ()
    forall l. l -> String -> Name l
    Ident () String
    "_" else Name ()
    v) (Type () -> Type ()) -> Type () -> Type ()
    forall a b. (a -> b) -> a -> b
    $ (SrcSpanInfo -> ()) -> Type SrcSpanInfo -> Type ()
    forall a b. (a -> b) -> Type a -> Type b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (() -> SrcSpanInfo -> ()
    forall a b. a -> b -> a
    const ()) Type SrcSpanInfo
    x
        ParseResult (Type SrcSpanInfo)
    _ -> Maybe (Type ())
    forall a. Maybe a
    Nothing
        where
            fixup :: [String] -> [String]
    fixup = [String] -> [String]
    underscore ([String] -> [String])
    -> ([String] -> [String]) -> [String] -> [String]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [String] -> [String]
    closeBracket ([String] -> [String])
    -> ([String] -> [String]) -> [String] -> [String]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [String] -> [String]
    forall {a}. (Eq a, IsString a) => [a] -> [a]
    completeFunc ([String] -> [String])
    -> ([String] -> [String]) -> [String] -> [String]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [String] -> [String]
    completeArrow

            completeArrow :: [String] -> [String]
    completeArrow ([String] -> Maybe ([String], String)
    forall a. [a] -> Maybe ([a], a)
    unsnoc -> Just ([String]
    a,String
    b)) | String
    b String -> [String] -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` [String
    "-",String
    "="] = [String] -> String -> [String]
    forall a. [a] -> a -> [a]
    snoc [String]
    a (String
    b String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    ">")
            completeArrow [String]
    x = [String]
    x

            completeFunc :: [a] -> [a]
    completeFunc ([a] -> Maybe ([a], a)
    forall a. [a] -> Maybe ([a], a)
    unsnoc -> Just ([a]
    a,a
    b)) | a
    b a -> [a] -> Bool
    forall a. Eq a => a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` [a
    "->",a
    "=>"] = [a]
    a [a] -> [a] -> [a]
    forall a. [a] -> [a] -> [a]
    ++ [a
    b,a
    "_"]
            completeFunc [a]
    x = [a]
    x

            closeBracket :: [String] -> [String]
    closeBracket [String]
    xs = [String]
    xs [String] -> [String] -> [String]
    forall a. [a] -> [a] -> [a]
    ++ ([String] -> String -> [String])
    -> [String] -> [String] -> [String]
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl [String] -> String -> [String]
    f [] [String]
    xs
                where f :: [String] -> String -> [String]
    f [String]
    stack String
    x | Just String
    c <- String -> [(String, String)] -> Maybe String
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup String
    x ([String] -> [String] -> [(String, String)]
    forall a b. [a] -> [b] -> [(a, b)]
    zip [String]
    openBrackets [String]
    shutBrackets) = String
    cString -> [String] -> [String]
    forall a. a -> [a] -> [a]
    :[String]
    stack
                      f (String
    s:[String]
    tack) String
    x | String
    x String -> String -> Bool
    forall a. Eq a => a -> a -> Bool
    == String
    s = [String]
    tack
                      f [String]
    stack String
    x = [String]
    stack

            underscore :: [String] -> [String]
    underscore = [String] -> [String] -> [String] -> [String]
    forall a. Eq a => [a] -> [a] -> [a] -> [a]
    replace [String
    "_"] [String
    "__"]

    query_test :: IO ()
    query_test :: IO ()
    query_test = String -> IO () -> IO ()
    testing String
    "Query.parseQuery" (IO () -> IO ()) -> IO () -> IO ()
    forall a b. (a -> b) -> a -> b
    $ do
        let want :: String -> (a -> Bool) -> (a, [a]) -> ([String], [a])
    want String
    s a -> Bool
    p (a
    bad,[a]
    q) = ([String
    "missing " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    s | Bool -> Bool
    not (Bool -> Bool) -> Bool -> Bool
    forall a b. (a -> b) -> a -> b
    $ (a -> Bool) -> [a] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    any a -> Bool
    p [a]
    q], (a -> Bool) -> [a] -> [a]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (Bool -> Bool
    not (Bool -> Bool) -> (a -> Bool) -> a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> Bool
    p) [a]
    q)
            wantEq :: a -> (a, [a]) -> ([String], [a])
    wantEq a
    v = String -> (a -> Bool) -> (a, [a]) -> ([String], [a])
    forall {a} {a}.
    String -> (a -> Bool) -> (a, [a]) -> ([String], [a])
    want (a -> String
    forall a. Show a => a -> String
    show a
    v) (a -> a -> Bool
    forall a. Eq a => a -> a -> Bool
    == a
    v)
            name :: String -> (a, [Query]) -> ([String], [Query])
    name = Query -> (a, [Query]) -> ([String], [Query])
    forall {a} {a}. (Show a, Eq a) => a -> (a, [a]) -> ([String], [a])
    wantEq (Query -> (a, [Query]) -> ([String], [Query]))
    -> (String -> Query)
    -> String
    -> (a, [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> Query
    QueryName
            scope :: Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    b String
    c String
    v = Query -> (a, [Query]) -> ([String], [Query])
    forall {a} {a}. (Show a, Eq a) => a -> (a, [a]) -> ([String], [a])
    wantEq (Query -> (a, [Query]) -> ([String], [Query]))
    -> Query -> (a, [Query]) -> ([String], [Query])
    forall a b. (a -> b) -> a -> b
    $ Bool -> String -> String -> Query
    QueryScope Bool
    b String
    c String
    v
            typ :: String -> (a, [Query]) -> ([String], [Query])
    typ = Query -> (a, [Query]) -> ([String], [Query])
    forall {a} {a}. (Show a, Eq a) => a -> (a, [a]) -> ([String], [a])
    wantEq (Query -> (a, [Query]) -> ([String], [Query]))
    -> (String -> Query)
    -> String
    -> (a, [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Type () -> Query
    QueryType (Type () -> Query) -> (String -> Type ()) -> String -> Query
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (SrcSpanInfo -> ()) -> Type SrcSpanInfo -> Type ()
    forall a b. (a -> b) -> Type a -> Type b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (() -> SrcSpanInfo -> ()
    forall a b. a -> b -> a
    const ()) (Type SrcSpanInfo -> Type ())
    -> (String -> Type SrcSpanInfo) -> String -> Type ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ParseResult (Type SrcSpanInfo) -> Type SrcSpanInfo
    forall a. ParseResult a -> a
    fromParseResult (ParseResult (Type SrcSpanInfo) -> Type SrcSpanInfo)
    -> (String -> ParseResult (Type SrcSpanInfo))
    -> String
    -> Type SrcSpanInfo
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ParseMode -> String -> ParseResult (Type SrcSpanInfo)
    parseTypeWithMode ParseMode
    parseMode
            typpp :: String -> (a, [Query]) -> ([String], [Query])
    typpp String
    x = String -> (Query -> Bool) -> (a, [Query]) -> ([String], [Query])
    forall {a} {a}.
    String -> (a -> Bool) -> (a, [a]) -> ([String], [a])
    want (String
    "type " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    x) (\Query
    v -> case Query
    v of QueryType Type ()
    s -> Type () -> String
    forall a. Pretty a => a -> String
    pretty Type ()
    s String -> String -> Bool
    forall a. Eq a => a -> a -> Bool
    == String
    x; Query
    _ -> Bool
    False)
        let infixl 0 ===
            String
    a === :: String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === ([a], [Query]) -> ([String], b)
    f | bad :: [String]
    bad@(String
    _:[String]
    _) <- ([String], b) -> [String]
    forall a b. (a, b) -> a
    fst (([String], b) -> [String]) -> ([String], b) -> [String]
    forall a b. (a -> b) -> a -> b
    $ ([a], [Query]) -> ([String], b)
    f ([], [Query]
    q) = String -> IO ()
    forall a. HasCallStack => String -> a
    error (String -> IO ()) -> String -> IO ()
    forall a b. (a -> b) -> a -> b
    $ (String, [Query], [String]) -> String
    forall a. Show a => a -> String
    show (String
    a,[Query]
    q,[String]
    bad :: [String])
                    | Bool
    otherwise = Char -> IO ()
    putChar Char
    '.'
                where q :: [Query]
    q = String -> [Query]
    parseQuery String
    a

        String
    "" String -> (([String], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === ([String], [Query]) -> ([String], [Query])
    forall a. a -> a
    id
        String
    "map" String -> (([ZonkAny 0], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 0], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "map"
        String
    "#" String -> (([ZonkAny 1], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 1], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "#"
        String
    "c#" String -> (([ZonkAny 2], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 2], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "c#"
        String
    "-" String -> (([ZonkAny 3], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 3], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "-"
        String
    "/" String -> (([ZonkAny 4], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 4], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "/"
        String
    "->" String -> (([ZonkAny 5], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 5], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "->"
        String
    "foldl'" String -> (([ZonkAny 6], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 6], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "foldl'"
        String
    "fold'l" String -> (([ZonkAny 7], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 7], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "fold'l"
        String
    "Int#" String -> (([ZonkAny 8], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 8], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "Int#"
        String
    "concat map" String -> (([ZonkAny 9], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "concat" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 9], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 9], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> ([ZonkAny 9], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "map"
        String
    "a -> b" String -> (([ZonkAny 10], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 10], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    typ String
    "a -> b"
        String
    "a->b" String -> (([ZonkAny 11], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 11], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    typ String
    "a -> b"
        String
    "(a b)" String -> (([ZonkAny 12], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 12], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    typ String
    "(a b)"
        String
    "map :: a -> b" String -> (([ZonkAny 13], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 13], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    typ String
    "a -> b"
        String
    "+Data.Map map" String -> (([ZonkAny 14], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === Bool
    -> String -> String -> ([String], [Query]) -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "module" String
    "Data.Map" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 14], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 14], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> ([ZonkAny 14], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "map"
        String
    "a -> b package:foo" String -> (([ZonkAny 15], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === Bool
    -> String -> String -> ([String], [Query]) -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "package" String
    "foo" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 15], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 15], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> ([ZonkAny 15], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    typ String
    "a -> b"
        String
    "a -> b package:foo-bar" String -> (([ZonkAny 16], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === Bool
    -> String -> String -> ([String], [Query]) -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "package" String
    "foo-bar" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 16], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 16], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> ([ZonkAny 16], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    typ String
    "a -> b"
        String
    "Data.Map.map" String -> (([ZonkAny 17], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === Bool
    -> String -> String -> ([String], [Query]) -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "module" String
    "Data.Map" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 17], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 17], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> ([ZonkAny 17], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "map"
        String
    "[a]" String -> (([ZonkAny 18], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 18], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    typ String
    "[a]"
        String
    "++" String -> (([ZonkAny 19], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 19], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "++"
        String
    "(++)" String -> (([ZonkAny 20], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 20], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "++"
        String
    ":+:" String -> (([ZonkAny 21], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 21], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    ":+:"
        String
    "bytestring-cvs +hackage" String -> (([ZonkAny 22], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === Bool
    -> String -> String -> ([String], [Query]) -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "package" String
    "hackage" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 22], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 22], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> ([ZonkAny 22], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "bytestring-cvs"
        String
    "m => c" String -> (([ZonkAny 23], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 23], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    typ String
    "m => c"
        String
    "[b ()" String -> (([ZonkAny 24], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 24], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    typ String
    "[b ()]"
        String
    "[b (" String -> (([ZonkAny 25], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 25], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    typ String
    "[b ()]"
        String
    "_ -> a" String -> (([ZonkAny 26], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 26], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    typpp String
    "_ -> a"
        String
    "(a -> b) ->" String -> (([ZonkAny 27], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 27], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    typpp String
    "(a -> b) -> _"
        String
    "(a -> b) -" String -> (([ZonkAny 28], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 28], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    typpp String
    "(a -> b) -> _"
        String
    "Monad m => " String -> (([ZonkAny 29], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 29], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    typpp String
    "Monad m => _"
        String
    "map is:exact" String -> (([ZonkAny 30], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "map" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 30], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 30], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 30], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "is" String
    "exact"
        String
    "sort set:hackage" String -> (([ZonkAny 31], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "sort" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 31], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 31], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 31], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "set" String
    "hackage"
        String
    "sort -set:hackage" String -> (([ZonkAny 32], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "sort" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 32], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 32], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 32], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    False String
    "set" String
    "hackage"
        String
    "sort set:-hackage" String -> (([ZonkAny 33], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "sort" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 33], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 33], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 33], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    False String
    "set" String
    "hackage"
        String
    "sort -set:-hackage" String -> (([ZonkAny 34], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "sort" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 34], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 34], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 34], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    False String
    "set" String
    "hackage"
        String
    "package:bytestring-csv" String -> (([ZonkAny 35], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === Bool
    -> String
    -> String
    -> ([ZonkAny 35], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "package" String
    "bytestring-csv"
        String
    "(>>=)" String -> (([ZonkAny 36], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 36], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    ">>="
        String
    "(>>=" String -> (([ZonkAny 37], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 37], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    ">>="
        String
    ">>=" String -> (([ZonkAny 38], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 38], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    ">>="
        String
    "Control.Monad.mplus" String -> (([ZonkAny 39], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "mplus" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 39], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 39], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 39], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "module" String
    "Control.Monad"
        String
    "Control.Monad.>>=" String -> (([ZonkAny 40], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    ">>=" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 40], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 40], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 40], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "module" String
    "Control.Monad"
        String
    "Control.Monad.(>>=)" String -> (([ZonkAny 41], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    ">>=" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 41], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 41], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 41], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "module" String
    "Control.Monad"
        String
    "(Control.Monad.>>=)" String -> (([ZonkAny 42], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    ">>=" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 42], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 42], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 42], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "module" String
    "Control.Monad"
        String
    "Control.Monad.(>>=" String -> (([ZonkAny 43], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    ">>=" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 43], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 43], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 43], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "module" String
    "Control.Monad"
        String
    "(Control.Monad.>>=" String -> (([ZonkAny 44], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    ">>=" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 44], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 44], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 44], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "module" String
    "Control.Monad"
        String
    "foo.bar" String -> (([ZonkAny 45], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "bar" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 45], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 45], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 45], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "package" String
    "foo"
        String
    "insert module:.Map" String -> (([ZonkAny 46], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "insert" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 46], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 46], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 46], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "module" String
    ".Map"
        String
    "insert module:Map." String -> (([ZonkAny 47], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "insert" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 47], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 47], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 47], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "module" String
    "Map."
        String
    "insert module:.Map." String -> (([ZonkAny 48], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "insert" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 48], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 48], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 48], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "module" String
    ".Map."
        String
    ".Map.insert" String -> (([ZonkAny 49], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "insert" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 49], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 49], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 49], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "module" String
    ".Map"
        String
    ".Map." String -> (([ZonkAny 50], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === Bool
    -> String
    -> String
    -> ([ZonkAny 50], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "module" String
    ".Map"
    --  FIXME: ".Map" === scope True "module" ".Map" -- probably should work, but really needs to rewrite a fair bit
        String
    "(.Monad.>>=" String -> (([ZonkAny 51], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([String], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    ">>=" (([String], [Query]) -> ([String], [Query]))
    -> (([ZonkAny 51], [Query]) -> ([String], [Query]))
    -> ([ZonkAny 51], [Query])
    -> ([String], [Query])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Bool
    -> String
    -> String
    -> ([ZonkAny 51], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "module" String
    ".Monad"
    --  FIXME: "author:Taylor-M.-Hedberg" === scope True "author" "Taylor-M.-Hedberg"
        String
    "author:Bryan-O'Sullivan" String -> (([ZonkAny 52], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === Bool
    -> String
    -> String
    -> ([ZonkAny 52], [Query])
    -> ([String], [Query])
    forall {a}.
    Bool -> String -> String -> (a, [Query]) -> ([String], [Query])
    scope Bool
    True String
    "author" String
    "Bryan-O'Sullivan"
        String
    "\8801" String -> (([ZonkAny 53], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === String -> ([ZonkAny 53], [Query]) -> ([String], [Query])
    forall {a}. String -> (a, [Query]) -> ([String], [Query])
    name String
    "\8801"
        String
    "( )" String -> (([String], [Query]) -> ([String], [Query])) -> IO ()
    forall {a} {b}.
    String -> (([a], [Query]) -> ([String], b)) -> IO ()
    === ([String], [Query]) -> ([String], [Query])
    forall a. a -> a
    id -- FIXME: Should probably be ()