    -- | Hackish Haddock module.
    module Lambdabot.Plugin.Haskell.Haddock (haddockPlugin) where

    import Lambdabot.Plugin

    import qualified Data.ByteString.Char8 as P
    import Data.List
    import qualified Data.Map as M

    type HaddockState = M.Map P.ByteString [P.ByteString]
    type Haddock = ModuleT HaddockState LB

    haddockPlugin :: Module HaddockState
    haddockPlugin :: Module HaddockState
    haddockPlugin = Module HaddockState
    forall st. Module st
    newModule
        { moduleCmds = return
            [ (command "index")
                { help = say "index <ident>. Returns the Haskell modules in which <ident> is defined"
                , process = doHaddock
                }
            ]

        , moduleDefState  = return M.empty
        , moduleSerialize = Just (readOnly readPacked)
        }

    doHaddock :: String -> Cmd Haddock ()
    doHaddock :: String -> Cmd Haddock ()
    doHaddock String
    k = do
        m <- Cmd Haddock HaddockState
    Cmd Haddock (LBState (Cmd Haddock))
    forall (m :: * -> *). MonadLBState m => m (LBState m)
    readMS
        say $ maybe "bzzt"
            (intercalate (", ") . map P.unpack)
            (M.lookup (stripPs (P.pack k)) m)

    -- make \@index ($) work.
    stripPs :: P.ByteString -> P.ByteString
    stripPs :: ByteString -> ByteString
    stripPs = (ByteString, ByteString) -> ByteString
    forall a b. (a, b) -> a
    fst ((ByteString, ByteString) -> ByteString)
    -> (ByteString -> (ByteString, ByteString))
    -> ByteString
    -> ByteString
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char -> Bool) -> ByteString -> (ByteString, ByteString)
    P.spanEnd (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    ==Char
    ')') (ByteString -> (ByteString, ByteString))
    -> (ByteString -> ByteString)
    -> ByteString
    -> (ByteString, ByteString)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (ByteString, ByteString) -> ByteString
    forall a b. (a, b) -> b
    snd ((ByteString, ByteString) -> ByteString)
    -> (ByteString -> (ByteString, ByteString))
    -> ByteString
    -> ByteString
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char -> Bool) -> ByteString -> (ByteString, ByteString)
    P.span (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    ==Char
    '(')