    {-# Language BlockArguments #-}
    {-# Language RecordWildCards #-}
    {-# Language FlexibleInstances #-}
    {-# LANGUAGE DeriveFunctor #-}
    {-# LANGUAGE DeriveTraversable #-}
    module Cryptol.ModuleSystem.Binds
      ( BindsNames
      , TopDef(..)
      , Mod(..)
      , ModKind(..)
      , modNested
      , modBuilder
      , topModuleDefs
      , topDeclsDefs
      , newModParam
      , InModule(..)
      , ifaceToMod
      , ifaceSigToMod
      , modToMap
      , defsOf
      ) where

    import Data.Map(Map)
    import qualified Data.Map as Map
    import Data.Set(Set)
    import qualified Data.Set as Set
    import Data.Maybe(fromMaybe)
    import Control.Monad(foldM)
    import qualified MonadLib as M

    import Cryptol.Utils.Panic (panic)
    import Cryptol.Utils.Ident(allNamespaces)
    import Cryptol.Parser.Position
    import Cryptol.Parser.Name(isGeneratedName)
    import Cryptol.Parser.AST
    import Cryptol.ModuleSystem.Exports(exportedDecls,exported)
    import Cryptol.ModuleSystem.Renamer.Error
    import Cryptol.ModuleSystem.Name
    import Cryptol.ModuleSystem.Names
    import Cryptol.ModuleSystem.NamingEnv
    import Cryptol.ModuleSystem.Interface
    import Cryptol.TypeCheck.Type(ModParamNames(..))

    data TopDef = TopMod ModName (Mod ())
                | TopInst ModName (ImpName PName) (ModuleInstanceArgs PName)

    -- | Things defined by a module
    data Mod a = Mod
      { forall a. Mod a -> [ImportG (ImpName PName)]
    modImports   :: [ ImportG (ImpName PName) ]
      , forall a. Mod a -> ModKind
    modKind      :: ModKind
      , forall a.
    Mod a -> Map Name (ImpName PName, ModuleInstanceArgs PName)
    modInstances :: Map Name (ImpName PName, ModuleInstanceArgs PName)
      , forall a. Mod a -> Map Name (Mod a)
    modMods      :: Map Name (Mod a) -- ^ this includes signatures

      , forall a. Mod a -> NamingEnv
    modDefines   :: NamingEnv
        {- ^ Things defined by this module.  Note the for normal modules we
        really just need the public names, however for things within
        functors we need all defined names, so that we can generate fresh
        names in instantiations -}

      , forall a. Mod a -> Set Name
    modPublic    :: !(Set Name)
        -- ^ These are the exported names

      , forall a. Mod a -> a
    modState     :: a
        {- ^ Used in the import loop to track the current state of processing.
             The reason this is here, rather than just having a pair in the
             other algorithm is because this type is recursive (for nested modules)
             and it is conveninet to keep track for all modules at once -}
      }

    modNested :: Mod a -> Set Name
    modNested :: forall a. Mod a -> Set Name
    modNested Mod a
    m = [Set Name] -> Set Name
    forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
    Set.unions [ Map Name (ImpName PName, ModuleInstanceArgs PName) -> Set Name
    forall k a. Map k a -> Set k
    Map.keysSet (Mod a -> Map Name (ImpName PName, ModuleInstanceArgs PName)
    forall a.
    Mod a -> Map Name (ImpName PName, ModuleInstanceArgs PName)
    modInstances Mod a
    m)
                             , Map Name (Mod a) -> Set Name
    forall k a. Map k a -> Set k
    Map.keysSet (Mod a -> Map Name (Mod a)
    forall a. Mod a -> Map Name (Mod a)
    modMods Mod a
    m)
                             ]

    instance Functor Mod where
      fmap :: forall a b. (a -> b) -> Mod a -> Mod b
    fmap a -> b
    f Mod a
    m = Mod a
    m { modState :: b
    modState = a -> b
    f (Mod a -> a
    forall a. Mod a -> a
    modState Mod a
    m)
                   , modMods :: Map Name (Mod b)
    modMods  = (a -> b) -> Mod a -> Mod b
    forall a b. (a -> b) -> Mod a -> Mod b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap a -> b
    f (Mod a -> Mod b) -> Map Name (Mod a) -> Map Name (Mod b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Mod a -> Map Name (Mod a)
    forall a. Mod a -> Map Name (Mod a)
    modMods Mod a
    m
                   }

    -- | Generate a map from this module and all modules nested in it.
    modToMap ::
      ImpName Name -> Mod () ->
      Map (ImpName Name) (Mod ()) -> Map (ImpName Name) (Mod ())
    modToMap :: ImpName Name
    -> Mod ()
    -> Map (ImpName Name) (Mod ())
    -> Map (ImpName Name) (Mod ())
    modToMap ImpName Name
    x Mod ()
    m Map (ImpName Name) (Mod ())
    mp = ImpName Name
    -> Mod ()
    -> Map (ImpName Name) (Mod ())
    -> Map (ImpName Name) (Mod ())
    forall k a. Ord k => k -> a -> Map k a -> Map k a
    Map.insert ImpName Name
    x Mod ()
    m ((Name
     -> Mod ()
     -> Map (ImpName Name) (Mod ())
     -> Map (ImpName Name) (Mod ()))
    -> Map (ImpName Name) (Mod ())
    -> Map Name (Mod ())
    -> Map (ImpName Name) (Mod ())
    forall k a b. (k -> a -> b -> b) -> b -> Map k a -> b
    Map.foldrWithKey Name
    -> Mod ()
    -> Map (ImpName Name) (Mod ())
    -> Map (ImpName Name) (Mod ())
    add Map (ImpName Name) (Mod ())
    mp (Mod () -> Map Name (Mod ())
    forall a. Mod a -> Map Name (Mod a)
    modMods Mod ()
    m))
      where
      add :: Name
    -> Mod ()
    -> Map (ImpName Name) (Mod ())
    -> Map (ImpName Name) (Mod ())
    add Name
    n = ImpName Name
    -> Mod ()
    -> Map (ImpName Name) (Mod ())
    -> Map (ImpName Name) (Mod ())
    modToMap (Name -> ImpName Name
    forall name. name -> ImpName name
    ImpNested Name
    n)

    -- | Make a `Mod` from the public declarations in an interface.
    -- This is used to handle imports.
    ifaceToMod :: IfaceG name -> Mod ()
    ifaceToMod :: forall name. IfaceG name -> Mod ()
    ifaceToMod IfaceG name
    iface = IfaceG name -> Bool -> IfaceNames name -> Mod ()
    forall topname name.
    IfaceG topname -> Bool -> IfaceNames name -> Mod ()
    ifaceNamesToMod IfaceG name
    iface (IfaceG name -> Bool
    forall name. IfaceG name -> Bool
    ifaceIsFunctor IfaceG name
    iface) (IfaceG name -> IfaceNames name
    forall name. IfaceG name -> IfaceNames name
    ifNames IfaceG name
    iface)

    ifaceNamesToMod :: IfaceG topname -> Bool -> IfaceNames name -> Mod ()
    ifaceNamesToMod :: forall topname name.
    IfaceG topname -> Bool -> IfaceNames name -> Mod ()
    ifaceNamesToMod IfaceG topname
    iface Bool
    params IfaceNames name
    names =
      Mod
        { modKind :: ModKind
    modKind    = if Bool
    params then ModKind
    AFunctor else ModKind
    AModule
        , modMods :: Map Name (Mod ())
    modMods    = (IfaceG topname -> Bool -> IfaceNames Name -> Mod ()
    forall topname name.
    IfaceG topname -> Bool -> IfaceNames name -> Mod ()
    ifaceNamesToMod IfaceG topname
    iface Bool
    False (IfaceNames Name -> Mod ())
    -> Map Name (IfaceNames Name) -> Map Name (Mod ())
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> IfaceDecls -> Map Name (IfaceNames Name)
    ifModules IfaceDecls
    decls)
                       Map Name (Mod ()) -> Map Name (Mod ()) -> Map Name (Mod ())
    forall k a. Ord k => Map k a -> Map k a -> Map k a
    `Map.union`
                       (IfaceG Name -> Mod ()
    forall name. IfaceG name -> Mod ()
    ifaceToMod (IfaceG Name -> Mod ())
    -> Map Name (IfaceG Name) -> Map Name (Mod ())
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> IfaceDecls -> Map Name (IfaceG Name)
    ifFunctors IfaceDecls
    decls)
                       Map Name (Mod ()) -> Map Name (Mod ()) -> Map Name (Mod ())
    forall k a. Ord k => Map k a -> Map k a -> Map k a
    `Map.union`
                       (ModParamNames -> Mod ()
    ifaceSigToMod (ModParamNames -> Mod ())
    -> Map Name ModParamNames -> Map Name (Mod ())
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> IfaceDecls -> Map Name ModParamNames
    ifSignatures IfaceDecls
    decls)
        , modDefines :: NamingEnv
    modDefines = Set Name -> NamingEnv
    namingEnvFromNames Set Name
    defs
        , modPublic :: Set Name
    modPublic  = IfaceNames name -> Set Name
    forall name. IfaceNames name -> Set Name
    ifsPublic IfaceNames name
    names

        , modImports :: [ImportG (ImpName PName)]
    modImports   = []
        , modInstances :: Map Name (ImpName PName, ModuleInstanceArgs PName)
    modInstances = Map Name (ImpName PName, ModuleInstanceArgs PName)
    forall a. Monoid a => a
    mempty
        , modState :: ()
    modState     = ()
        }
      where
      defs :: Set Name
    defs      = IfaceNames name -> Set Name
    forall name. IfaceNames name -> Set Name
    ifsDefines IfaceNames name
    names
      isLocal :: Name -> Bool
    isLocal Name
    x = Name
    x Name -> Set Name -> Bool
    forall a. Ord a => a -> Set a -> Bool
    `Set.member` Set Name
    defs
      decls :: IfaceDecls
    decls     = (Name -> Bool) -> IfaceDecls -> IfaceDecls
    filterIfaceDecls Name -> Bool
    isLocal (IfaceG topname -> IfaceDecls
    forall name. IfaceG name -> IfaceDecls
    ifDefines IfaceG topname
    iface)

    ifaceSigToMod :: ModParamNames -> Mod ()
    ifaceSigToMod :: ModParamNames -> Mod ()
    ifaceSigToMod ModParamNames
    ps = Mod
      { modImports :: [ImportG (ImpName PName)]
    modImports   = []
      , modKind :: ModKind
    modKind      = ModKind
    ASignature
      , modInstances :: Map Name (ImpName PName, ModuleInstanceArgs PName)
    modInstances = Map Name (ImpName PName, ModuleInstanceArgs PName)
    forall a. Monoid a => a
    mempty
      , modMods :: Map Name (Mod ())
    modMods      = Map Name (Mod ())
    forall a. Monoid a => a
    mempty
      , modDefines :: NamingEnv
    modDefines   = NamingEnv
    env
      , modPublic :: Set Name
    modPublic    = NamingEnv -> Set Name
    namingEnvNames NamingEnv
    env
      , modState :: ()
    modState     = ()
      }
      where
      env :: NamingEnv
    env = ModParamNames -> NamingEnv
    modParamsNamingEnv ModParamNames
    ps

    type ModBuilder = SupplyT (M.StateT [RenamerError] M.Id)

    modBuilder :: ModBuilder a -> Supply -> ((a, [RenamerError]),Supply)
    modBuilder :: forall a. ModBuilder a -> Supply -> ((a, [RenamerError]), Supply)
    modBuilder ModBuilder a
    m Supply
    s = ((a
    a,[RenamerError]
    errs),Supply
    s1)
      where ((a
    a,Supply
    s1),[RenamerError]
    errs) = Id ((a, Supply), [RenamerError]) -> ((a, Supply), [RenamerError])
    forall a. Id a -> a
    M.runId ([RenamerError]
    -> StateT [RenamerError] Id (a, Supply)
    -> Id ((a, Supply), [RenamerError])
    forall i (m :: * -> *) a. i -> StateT i m a -> m (a, i)
    M.runStateT [] (Supply -> ModBuilder a -> StateT [RenamerError] Id (a, Supply)
    forall (m :: * -> *) a.
    Monad m =>
    Supply -> SupplyT m a -> m (a, Supply)
    runSupplyT Supply
    s ModBuilder a
    m))

    defErr :: RenamerError -> ModBuilder ()
    defErr :: RenamerError -> ModBuilder ()
    defErr RenamerError
    a = StateT [RenamerError] Id () -> ModBuilder ()
    forall (m :: * -> *) a. Monad m => m a -> SupplyT m a
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
    (MonadT t, Monad m) =>
    m a -> t m a
    M.lift (([RenamerError] -> [RenamerError]) -> StateT [RenamerError] Id ()
    forall (m :: * -> *) s. StateM m s => (s -> s) -> m ()
    M.sets_ (RenamerError
    aRenamerError -> [RenamerError] -> [RenamerError]
    forall a. a -> [a] -> [a]
    :))

    defNames :: BuildNamingEnv -> ModBuilder NamingEnv
    defNames :: BuildNamingEnv -> ModBuilder NamingEnv
    defNames BuildNamingEnv
    b = (Supply -> (NamingEnv, Supply)) -> ModBuilder NamingEnv
    forall a.
    (Supply -> (a, Supply)) -> SupplyT (StateT [RenamerError] Id) a
    forall (m :: * -> *) a. FreshM m => (Supply -> (a, Supply)) -> m a
    liftSupply \Supply
    s -> Id (NamingEnv, Supply) -> (NamingEnv, Supply)
    forall a. Id a -> a
    M.runId (Supply -> SupplyT Id NamingEnv -> Id (NamingEnv, Supply)
    forall (m :: * -> *) a.
    Monad m =>
    Supply -> SupplyT m a -> m (a, Supply)
    runSupplyT Supply
    s (BuildNamingEnv -> SupplyT Id NamingEnv
    runBuild BuildNamingEnv
    b))

    topModuleDefs :: Module PName -> ModBuilder TopDef
    topModuleDefs :: Module PName -> ModBuilder TopDef
    topModuleDefs Module PName
    m =
      case Module PName -> ModuleDefinition PName
    forall mname name. ModuleG mname name -> ModuleDefinition name
    mDef Module PName
    m of
        NormalModule [TopDecl PName]
    ds -> ModName -> Mod () -> TopDef
    TopMod ModName
    mname (Mod () -> TopDef)
    -> SupplyT (StateT [RenamerError] Id) (Mod ()) -> ModBuilder TopDef
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Maybe ModPath
    -> [TopDecl PName] -> SupplyT (StateT [RenamerError] Id) (Mod ())
    declsToMod (ModPath -> Maybe ModPath
    forall a. a -> Maybe a
    Just (ModName -> ModPath
    TopModule ModName
    mname)) [TopDecl PName]
    ds
        FunctorInstance Located (ImpName PName)
    f ModuleInstanceArgs PName
    as ModuleInstance PName
    _ -> TopDef -> ModBuilder TopDef
    forall a. a -> SupplyT (StateT [RenamerError] Id) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (ModName -> ImpName PName -> ModuleInstanceArgs PName -> TopDef
    TopInst ModName
    mname (Located (ImpName PName) -> ImpName PName
    forall a. Located a -> a
    thing Located (ImpName PName)
    f) ModuleInstanceArgs PName
    as)
        InterfaceModule Signature PName
    s -> ModName -> Mod () -> TopDef
    TopMod ModName
    mname (Mod () -> TopDef)
    -> SupplyT (StateT [RenamerError] Id) (Mod ()) -> ModBuilder TopDef
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ModPath
    -> Signature PName -> SupplyT (StateT [RenamerError] Id) (Mod ())
    sigToMod (ModName -> ModPath
    TopModule ModName
    mname) Signature PName
    s
      where
      mname :: ModName
    mname = Located ModName -> ModName
    forall a. Located a -> a
    thing (Module PName -> Located ModName
    forall mname name. ModuleG mname name -> Located mname
    mName Module PName
    m)

    topDeclsDefs :: ModPath -> [TopDecl PName] -> ModBuilder (Mod ())
    topDeclsDefs :: ModPath
    -> [TopDecl PName] -> SupplyT (StateT [RenamerError] Id) (Mod ())
    topDeclsDefs = Maybe ModPath
    -> [TopDecl PName] -> SupplyT (StateT [RenamerError] Id) (Mod ())
    declsToMod (Maybe ModPath
     -> [TopDecl PName] -> SupplyT (StateT [RenamerError] Id) (Mod ()))
    -> (ModPath -> Maybe ModPath)
    -> ModPath
    -> [TopDecl PName]
    -> SupplyT (StateT [RenamerError] Id) (Mod ())
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ModPath -> Maybe ModPath
    forall a. a -> Maybe a
    Just

    sigToMod :: ModPath -> Signature PName -> ModBuilder (Mod ())
    sigToMod :: ModPath
    -> Signature PName -> SupplyT (StateT [RenamerError] Id) (Mod ())
    sigToMod ModPath
    mp Signature PName
    sig =
      do NamingEnv
    env <- BuildNamingEnv -> ModBuilder NamingEnv
    defNames (ModPath -> Signature PName -> BuildNamingEnv
    signatureDefs ModPath
    mp Signature PName
    sig)
         Mod () -> SupplyT (StateT [RenamerError] Id) (Mod ())
    forall a. a -> SupplyT (StateT [RenamerError] Id) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Mod { modImports :: [ImportG (ImpName PName)]
    modImports   = (Located (ImportG (ImpName PName)) -> ImportG (ImpName PName))
    -> [Located (ImportG (ImpName PName))] -> [ImportG (ImpName PName)]
    forall a b. (a -> b) -> [a] -> [b]
    map Located (ImportG (ImpName PName)) -> ImportG (ImpName PName)
    forall a. Located a -> a
    thing (Signature PName -> [Located (ImportG (ImpName PName))]
    forall name. Signature name -> [Located (ImportG (ImpName name))]
    sigImports Signature PName
    sig)
                  , modKind :: ModKind
    modKind      = ModKind
    ASignature
                  , modInstances :: Map Name (ImpName PName, ModuleInstanceArgs PName)
    modInstances = Map Name (ImpName PName, ModuleInstanceArgs PName)
    forall a. Monoid a => a
    mempty
                  , modMods :: Map Name (Mod ())
    modMods      = Map Name (Mod ())
    forall a. Monoid a => a
    mempty
                  , modDefines :: NamingEnv
    modDefines   = NamingEnv
    env
                  , modPublic :: Set Name
    modPublic    = NamingEnv -> Set Name
    namingEnvNames NamingEnv
    env
                  , modState :: ()
    modState     = ()
                  }

    declsToMod :: Maybe ModPath -> [TopDecl PName] -> ModBuilder (Mod ())
    declsToMod :: Maybe ModPath
    -> [TopDecl PName] -> SupplyT (StateT [RenamerError] Id) (Mod ())
    declsToMod Maybe ModPath
    mbPath [TopDecl PName]
    ds =
      do NamingEnv
    defs <- BuildNamingEnv -> ModBuilder NamingEnv
    defNames ((TopDecl PName -> BuildNamingEnv)
    -> [TopDecl PName] -> BuildNamingEnv
    forall m a. Monoid m => (a -> m) -> [a] -> m
    forall (t :: * -> *) m a.
    (Foldable t, Monoid m) =>
    (a -> m) -> t a -> m
    foldMap (InModule (TopDecl PName) -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv (InModule (TopDecl PName) -> BuildNamingEnv)
    -> (TopDecl PName -> InModule (TopDecl PName))
    -> TopDecl PName
    -> BuildNamingEnv
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Maybe ModPath -> TopDecl PName -> InModule (TopDecl PName)
    forall a. Maybe ModPath -> a -> InModule a
    InModule Maybe ModPath
    mbPath) [TopDecl PName]
    ds)
         let expSpec :: ExportSpec PName
    expSpec = [TopDecl PName] -> ExportSpec PName
    forall name. Ord name => [TopDecl name] -> ExportSpec name
    exportedDecls [TopDecl PName]
    ds
         let pub :: Set Name
    pub     = [Name] -> Set Name
    forall a. Ord a => [a] -> Set a
    Set.fromList
                         [ Name
    name
                         | Namespace
    ns    <- [Namespace]
    allNamespaces
                         , PName
    pname <- Set PName -> [PName]
    forall a. Set a -> [a]
    Set.toList (Namespace -> ExportSpec PName -> Set PName
    forall name. Namespace -> ExportSpec name -> Set name
    exported Namespace
    ns ExportSpec PName
    expSpec)
                         , Name
    name  <- Namespace -> PName -> NamingEnv -> [Name]
    lookupListNS Namespace
    ns PName
    pname NamingEnv
    defs
                         ]

         case NamingEnv -> [[Name]]
    findAmbig NamingEnv
    defs of
           bad :: [Name]
    bad@(Name
    _ : [Name]
    _) : [[Name]]
    _ ->
             -- defErr (MultipleDefinitions mbPath (nameIdent f) (map nameLoc bad))
             RenamerError -> ModBuilder ()
    defErr ([Name] -> RenamerError
    OverlappingSyms [Name]
    bad)
           [[Name]]
    _ -> () -> ModBuilder ()
    forall a. a -> SupplyT (StateT [RenamerError] Id) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure ()

         let mo :: Mod ()
    mo = Mod { modImports :: [ImportG (ImpName PName)]
    modImports      = [ Located (ImportG (ImpName PName)) -> ImportG (ImpName PName)
    forall a. Located a -> a
    thing Located (ImportG (ImpName PName))
    i | DImport Located (ImportG (ImpName PName))
    i <- [TopDecl PName]
    ds ]
                      , modKind :: ModKind
    modKind         = if (TopDecl PName -> Bool) -> [TopDecl PName] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    any TopDecl PName -> Bool
    forall a. TopDecl a -> Bool
    isParamDecl [TopDecl PName]
    ds
                                             then ModKind
    AFunctor else ModKind
    AModule
                      , modInstances :: Map Name (ImpName PName, ModuleInstanceArgs PName)
    modInstances    = Map Name (ImpName PName, ModuleInstanceArgs PName)
    forall a. Monoid a => a
    mempty
                      , modMods :: Map Name (Mod ())
    modMods         = Map Name (Mod ())
    forall a. Monoid a => a
    mempty
                      , modDefines :: NamingEnv
    modDefines      = NamingEnv
    defs
                      , modPublic :: Set Name
    modPublic       = Set Name
    pub
                      , modState :: ()
    modState        = ()
                      }

         (Mod ()
     -> TopDecl PName -> SupplyT (StateT [RenamerError] Id) (Mod ()))
    -> Mod ()
    -> [TopDecl PName]
    -> SupplyT (StateT [RenamerError] Id) (Mod ())
    forall (t :: * -> *) (m :: * -> *) b a.
    (Foldable t, Monad m) =>
    (b -> a -> m b) -> b -> t a -> m b
    foldM (NamingEnv
    -> Mod ()
    -> TopDecl PName
    -> SupplyT (StateT [RenamerError] Id) (Mod ())
    checkNest NamingEnv
    defs) Mod ()
    mo [TopDecl PName]
    ds

      where
      checkNest :: NamingEnv
    -> Mod ()
    -> TopDecl PName
    -> SupplyT (StateT [RenamerError] Id) (Mod ())
    checkNest NamingEnv
    defs Mod ()
    mo TopDecl PName
    d =
        case TopDecl PName
    d of
          DModule TopLevel (NestedModule PName)
    tl ->
            do let NestedModule ModuleG PName PName
    nmod = TopLevel (NestedModule PName) -> NestedModule PName
    forall a. TopLevel a -> a
    tlValue TopLevel (NestedModule PName)
    tl
                   pname :: PName
    pname = Located PName -> PName
    forall a. Located a -> a
    thing (ModuleG PName PName -> Located PName
    forall mname name. ModuleG mname name -> Located mname
    mName ModuleG PName PName
    nmod)
                   name :: Name
    name  = case Namespace -> PName -> NamingEnv -> Maybe Names
    lookupNS Namespace
    NSModule PName
    pname NamingEnv
    defs of
                             Just Names
    xs -> Names -> Name
    anyOne Names
    xs
                             Maybe Names
    _ -> String -> [String] -> Name
    forall a. HasCallStack => String -> [String] -> a
    panic String
    "declsToMod" [String
    "undefined name", PName -> String
    forall a. Show a => a -> String
    show PName
    pname]
               case Maybe ModPath
    mbPath of
                 Maybe ModPath
    Nothing ->
                   do RenamerError -> ModBuilder ()
    defErr (Range -> PName -> RenamerError
    UnexpectedNest (Located PName -> Range
    forall a. Located a -> Range
    srcRange (ModuleG PName PName -> Located PName
    forall mname name. ModuleG mname name -> Located mname
    mName ModuleG PName PName
    nmod)) PName
    pname)
                      Mod () -> SupplyT (StateT [RenamerError] Id) (Mod ())
    forall a. a -> SupplyT (StateT [RenamerError] Id) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Mod ()
    mo
                 Just ModPath
    path ->
                    case ModuleG PName PName -> ModuleDefinition PName
    forall mname name. ModuleG mname name -> ModuleDefinition name
    mDef ModuleG PName PName
    nmod of

                       NormalModule [TopDecl PName]
    xs ->
                         do Mod ()
    m <- Maybe ModPath
    -> [TopDecl PName] -> SupplyT (StateT [RenamerError] Id) (Mod ())
    declsToMod (ModPath -> Maybe ModPath
    forall a. a -> Maybe a
    Just (ModPath -> Ident -> ModPath
    Nested ModPath
    path (Name -> Ident
    nameIdent Name
    name))) [TopDecl PName]
    xs
                            Mod () -> SupplyT (StateT [RenamerError] Id) (Mod ())
    forall a. a -> SupplyT (StateT [RenamerError] Id) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Mod ()
    mo { modMods :: Map Name (Mod ())
    modMods = Name -> Mod () -> Map Name (Mod ()) -> Map Name (Mod ())
    forall k a. Ord k => k -> a -> Map k a -> Map k a
    Map.insert Name
    name Mod ()
    m (Mod () -> Map Name (Mod ())
    forall a. Mod a -> Map Name (Mod a)
    modMods Mod ()
    mo) }

                       FunctorInstance Located (ImpName PName)
    f ModuleInstanceArgs PName
    args ModuleInstance PName
    _ ->
                          Mod () -> SupplyT (StateT [RenamerError] Id) (Mod ())
    forall a. a -> SupplyT (StateT [RenamerError] Id) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Mod ()
    mo { modInstances :: Map Name (ImpName PName, ModuleInstanceArgs PName)
    modInstances = Name
    -> (ImpName PName, ModuleInstanceArgs PName)
    -> Map Name (ImpName PName, ModuleInstanceArgs PName)
    -> Map Name (ImpName PName, ModuleInstanceArgs PName)
    forall k a. Ord k => k -> a -> Map k a -> Map k a
    Map.insert Name
    name (Located (ImpName PName) -> ImpName PName
    forall a. Located a -> a
    thing Located (ImpName PName)
    f, ModuleInstanceArgs PName
    args)
                                                        (Mod () -> Map Name (ImpName PName, ModuleInstanceArgs PName)
    forall a.
    Mod a -> Map Name (ImpName PName, ModuleInstanceArgs PName)
    modInstances Mod ()
    mo) }

                       InterfaceModule Signature PName
    sig ->
                          do Mod ()
    m <- ModPath
    -> Signature PName -> SupplyT (StateT [RenamerError] Id) (Mod ())
    sigToMod (ModPath -> Ident -> ModPath
    Nested ModPath
    path (Name -> Ident
    nameIdent Name
    name)) Signature PName
    sig
                             Mod () -> SupplyT (StateT [RenamerError] Id) (Mod ())
    forall a. a -> SupplyT (StateT [RenamerError] Id) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Mod ()
    mo { modMods :: Map Name (Mod ())
    modMods = Name -> Mod () -> Map Name (Mod ()) -> Map Name (Mod ())
    forall k a. Ord k => k -> a -> Map k a -> Map k a
    Map.insert Name
    name Mod ()
    m (Mod () -> Map Name (Mod ())
    forall a. Mod a -> Map Name (Mod a)
    modMods Mod ()
    mo) }

          TopDecl PName
    _ -> Mod () -> SupplyT (StateT [RenamerError] Id) (Mod ())
    forall a. a -> SupplyT (StateT [RenamerError] Id) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Mod ()
    mo

    -- | These are the names "owned" by the signature.  These names are
    -- used when resolving the signature.  They are also used to figure out what
    -- names to instantuate when the signature is used.
    signatureDefs :: ModPath -> Signature PName -> BuildNamingEnv
    signatureDefs :: ModPath -> Signature PName -> BuildNamingEnv
    signatureDefs ModPath
    m Signature PName
    sig =
         [BuildNamingEnv] -> BuildNamingEnv
    forall a. Monoid a => [a] -> a
    mconcat [ InModule (ParameterType PName) -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv (Maybe ModPath
    -> ParameterType PName -> InModule (ParameterType PName)
    forall a. Maybe ModPath -> a -> InModule a
    InModule Maybe ModPath
    loc ParameterType PName
    p) | ParameterType PName
    p <- Signature PName -> [ParameterType PName]
    forall name. Signature name -> [ParameterType name]
    sigTypeParams Signature PName
    sig ]
      BuildNamingEnv -> BuildNamingEnv -> BuildNamingEnv
    forall a. Semigroup a => a -> a -> a
    <> [BuildNamingEnv] -> BuildNamingEnv
    forall a. Monoid a => [a] -> a
    mconcat [ InModule (ParameterFun PName) -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv (Maybe ModPath
    -> ParameterFun PName -> InModule (ParameterFun PName)
    forall a. Maybe ModPath -> a -> InModule a
    InModule Maybe ModPath
    loc ParameterFun PName
    p) | ParameterFun PName
    p <- Signature PName -> [ParameterFun PName]
    forall name. Signature name -> [ParameterFun name]
    sigFunParams Signature PName
    sig ]
      BuildNamingEnv -> BuildNamingEnv -> BuildNamingEnv
    forall a. Semigroup a => a -> a -> a
    <> [BuildNamingEnv] -> BuildNamingEnv
    forall a. Monoid a => [a] -> a
    mconcat [ InModule (SigDecl PName) -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv (Maybe ModPath -> SigDecl PName -> InModule (SigDecl PName)
    forall a. Maybe ModPath -> a -> InModule a
    InModule Maybe ModPath
    loc SigDecl PName
    p) | SigDecl PName
    p <- Signature PName -> [SigDecl PName]
    forall name. Signature name -> [SigDecl name]
    sigDecls Signature PName
    sig ]
      where
      loc :: Maybe ModPath
    loc = ModPath -> Maybe ModPath
    forall a. a -> Maybe a
    Just ModPath
    m
    --------------------------------------------------------------------------------

    --------------------------------------------------------------------------------
    -- Computes the names introduced by various declarations.

    -- | Things that define exported names.
    class BindsNames a where
      namingEnv :: a -> BuildNamingEnv

    newtype BuildNamingEnv = BuildNamingEnv { BuildNamingEnv -> SupplyT Id NamingEnv
    runBuild :: SupplyT M.Id NamingEnv }

    buildNamingEnv :: BuildNamingEnv -> Supply -> (NamingEnv,Supply)
    buildNamingEnv :: BuildNamingEnv -> Supply -> (NamingEnv, Supply)
    buildNamingEnv BuildNamingEnv
    b Supply
    supply = Id (NamingEnv, Supply) -> (NamingEnv, Supply)
    forall a. Id a -> a
    M.runId (Id (NamingEnv, Supply) -> (NamingEnv, Supply))
    -> Id (NamingEnv, Supply) -> (NamingEnv, Supply)
    forall a b. (a -> b) -> a -> b
    $ Supply -> SupplyT Id NamingEnv -> Id (NamingEnv, Supply)
    forall (m :: * -> *) a.
    Monad m =>
    Supply -> SupplyT m a -> m (a, Supply)
    runSupplyT Supply
    supply (SupplyT Id NamingEnv -> Id (NamingEnv, Supply))
    -> SupplyT Id NamingEnv -> Id (NamingEnv, Supply)
    forall a b. (a -> b) -> a -> b
    $ BuildNamingEnv -> SupplyT Id NamingEnv
    runBuild BuildNamingEnv
    b

    -- | Generate a 'NamingEnv' using an explicit supply.
    defsOf :: BindsNames a => a -> Supply -> (NamingEnv,Supply)
    defsOf :: forall a. BindsNames a => a -> Supply -> (NamingEnv, Supply)
    defsOf = BuildNamingEnv -> Supply -> (NamingEnv, Supply)
    buildNamingEnv (BuildNamingEnv -> Supply -> (NamingEnv, Supply))
    -> (a -> BuildNamingEnv) -> a -> Supply -> (NamingEnv, Supply)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . a -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv

    instance Semigroup BuildNamingEnv where
      BuildNamingEnv SupplyT Id NamingEnv
    a <> :: BuildNamingEnv -> BuildNamingEnv -> BuildNamingEnv
    <> BuildNamingEnv SupplyT Id NamingEnv
    b = SupplyT Id NamingEnv -> BuildNamingEnv
    BuildNamingEnv (SupplyT Id NamingEnv -> BuildNamingEnv)
    -> SupplyT Id NamingEnv -> BuildNamingEnv
    forall a b. (a -> b) -> a -> b
    $
        do NamingEnv
    x <- SupplyT Id NamingEnv
    a
           NamingEnv
    y <- SupplyT Id NamingEnv
    b
           NamingEnv -> SupplyT Id NamingEnv
    forall a. a -> SupplyT Id a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (NamingEnv -> NamingEnv -> NamingEnv
    forall a. Monoid a => a -> a -> a
    mappend NamingEnv
    x NamingEnv
    y)

    instance Monoid BuildNamingEnv where
      mempty :: BuildNamingEnv
    mempty = SupplyT Id NamingEnv -> BuildNamingEnv
    BuildNamingEnv (NamingEnv -> SupplyT Id NamingEnv
    forall a. a -> SupplyT Id a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure NamingEnv
    forall a. Monoid a => a
    mempty)

      mappend :: BuildNamingEnv -> BuildNamingEnv -> BuildNamingEnv
    mappend = BuildNamingEnv -> BuildNamingEnv -> BuildNamingEnv
    forall a. Semigroup a => a -> a -> a
    (<>)

      mconcat :: [BuildNamingEnv] -> BuildNamingEnv
    mconcat [BuildNamingEnv]
    bs = SupplyT Id NamingEnv -> BuildNamingEnv
    BuildNamingEnv (SupplyT Id NamingEnv -> BuildNamingEnv)
    -> SupplyT Id NamingEnv -> BuildNamingEnv
    forall a b. (a -> b) -> a -> b
    $
        do [NamingEnv]
    ns <- [SupplyT Id NamingEnv] -> SupplyT Id [NamingEnv]
    forall (t :: * -> *) (m :: * -> *) a.
    (Traversable t, Monad m) =>
    t (m a) -> m (t a)
    forall (m :: * -> *) a. Monad m => [m a] -> m [a]
    sequence ((BuildNamingEnv -> SupplyT Id NamingEnv)
    -> [BuildNamingEnv] -> [SupplyT Id NamingEnv]
    forall a b. (a -> b) -> [a] -> [b]
    map BuildNamingEnv -> SupplyT Id NamingEnv
    runBuild [BuildNamingEnv]
    bs)
           NamingEnv -> SupplyT Id NamingEnv
    forall a. a -> SupplyT Id a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([NamingEnv] -> NamingEnv
    forall a. Monoid a => [a] -> a
    mconcat [NamingEnv]
    ns)

    instance BindsNames NamingEnv where
      namingEnv :: NamingEnv -> BuildNamingEnv
    namingEnv NamingEnv
    env = SupplyT Id NamingEnv -> BuildNamingEnv
    BuildNamingEnv (NamingEnv -> SupplyT Id NamingEnv
    forall a. a -> SupplyT Id a
    forall (m :: * -> *) a. Monad m => a -> m a
    return NamingEnv
    env)
      {-# INLINE namingEnv #-}

    instance BindsNames a => BindsNames (Maybe a) where
      namingEnv :: Maybe a -> BuildNamingEnv
    namingEnv = (a -> BuildNamingEnv) -> Maybe a -> BuildNamingEnv
    forall m a. Monoid m => (a -> m) -> Maybe a -> m
    forall (t :: * -> *) m a.
    (Foldable t, Monoid m) =>
    (a -> m) -> t a -> m
    foldMap a -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv
      {-# INLINE namingEnv #-}

    instance BindsNames a => BindsNames [a] where
      namingEnv :: [a] -> BuildNamingEnv
    namingEnv = (a -> BuildNamingEnv) -> [a] -> BuildNamingEnv
    forall m a. Monoid m => (a -> m) -> [a] -> m
    forall (t :: * -> *) m a.
    (Foldable t, Monoid m) =>
    (a -> m) -> t a -> m
    foldMap a -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv
      {-# INLINE namingEnv #-}

    -- | Generate a type renaming environment from the parameters that are bound by
    -- this schema.
    instance BindsNames (Schema PName) where
      namingEnv :: Schema PName -> BuildNamingEnv
    namingEnv (Forall [TParam PName]
    ps [Prop PName]
    _ Type PName
    _ Maybe Range
    _) = (TParam PName -> BuildNamingEnv)
    -> [TParam PName] -> BuildNamingEnv
    forall m a. Monoid m => (a -> m) -> [a] -> m
    forall (t :: * -> *) m a.
    (Foldable t, Monoid m) =>
    (a -> m) -> t a -> m
    foldMap TParam PName -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv [TParam PName]
    ps
      {-# INLINE namingEnv #-}

    -- | Introduce the name
    instance BindsNames (InModule (Bind PName)) where
      namingEnv :: InModule (Bind PName) -> BuildNamingEnv
    namingEnv (InModule Maybe ModPath
    mb Bind PName
    b) = SupplyT Id NamingEnv -> BuildNamingEnv
    BuildNamingEnv (SupplyT Id NamingEnv -> BuildNamingEnv)
    -> SupplyT Id NamingEnv -> BuildNamingEnv
    forall a b. (a -> b) -> a -> b
    $
        do let Located { Range
    PName
    thing :: forall a. Located a -> a
    srcRange :: forall a. Located a -> Range
    srcRange :: Range
    thing :: PName
    .. } = Bind PName -> Located PName
    forall name. Bind name -> Located name
    bName Bind PName
    b
           Name
    n <- case Maybe ModPath
    mb of
                  Just ModPath
    m  -> Namespace
    -> ModPath -> PName -> Maybe Fixity -> Range -> SupplyT Id Name
    forall (m :: * -> *).
    FreshM m =>
    Namespace -> ModPath -> PName -> Maybe Fixity -> Range -> m Name
    newTop Namespace
    NSValue ModPath
    m PName
    thing (Bind PName -> Maybe Fixity
    forall name. Bind name -> Maybe Fixity
    bFixity Bind PName
    b) Range
    srcRange
                  Maybe ModPath
    Nothing -> Namespace -> PName -> Range -> SupplyT Id Name
    forall (m :: * -> *).
    FreshM m =>
    Namespace -> PName -> Range -> m Name
    newLocal Namespace
    NSValue PName
    thing Range
    srcRange -- local fixitiies?

           NamingEnv -> SupplyT Id NamingEnv
    forall a. a -> SupplyT Id a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Namespace -> PName -> Name -> NamingEnv
    singletonNS Namespace
    NSValue PName
    thing Name
    n)

    -- | Generate the naming environment for a type parameter.
    instance BindsNames (TParam PName) where
      namingEnv :: TParam PName -> BuildNamingEnv
    namingEnv TParam { Maybe Range
    Maybe Kind
    PName
    tpName :: PName
    tpKind :: Maybe Kind
    tpRange :: Maybe Range
    tpName :: forall n. TParam n -> n
    tpKind :: forall n. TParam n -> Maybe Kind
    tpRange :: forall n. TParam n -> Maybe Range
    .. } = SupplyT Id NamingEnv -> BuildNamingEnv
    BuildNamingEnv (SupplyT Id NamingEnv -> BuildNamingEnv)
    -> SupplyT Id NamingEnv -> BuildNamingEnv
    forall a b. (a -> b) -> a -> b
    $
        do let range :: Range
    range = Range -> Maybe Range -> Range
    forall a. a -> Maybe a -> a
    fromMaybe Range
    emptyRange Maybe Range
    tpRange
           Name
    n <- Namespace -> PName -> Range -> SupplyT Id Name
    forall (m :: * -> *).
    FreshM m =>
    Namespace -> PName -> Range -> m Name
    newLocal Namespace
    NSType PName
    tpName Range
    range
           NamingEnv -> SupplyT Id NamingEnv
    forall a. a -> SupplyT Id a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Namespace -> PName -> Name -> NamingEnv
    singletonNS Namespace
    NSType PName
    tpName Name
    n)

    instance BindsNames (InModule (TopDecl PName)) where
      namingEnv :: InModule (TopDecl PName) -> BuildNamingEnv
    namingEnv (InModule Maybe ModPath
    ns TopDecl PName
    td) =
        case TopDecl PName
    td of
          Decl TopLevel (Decl PName)
    d           -> InModule (Decl PName) -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv (Maybe ModPath -> Decl PName -> InModule (Decl PName)
    forall a. Maybe ModPath -> a -> InModule a
    InModule Maybe ModPath
    ns (TopLevel (Decl PName) -> Decl PName
    forall a. TopLevel a -> a
    tlValue TopLevel (Decl PName)
    d))
          DPrimType TopLevel (PrimType PName)
    d      -> InModule (PrimType PName) -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv (Maybe ModPath -> PrimType PName -> InModule (PrimType PName)
    forall a. Maybe ModPath -> a -> InModule a
    InModule Maybe ModPath
    ns (TopLevel (PrimType PName) -> PrimType PName
    forall a. TopLevel a -> a
    tlValue TopLevel (PrimType PName)
    d))
          TDNewtype TopLevel (Newtype PName)
    d      -> InModule (Newtype PName) -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv (Maybe ModPath -> Newtype PName -> InModule (Newtype PName)
    forall a. Maybe ModPath -> a -> InModule a
    InModule Maybe ModPath
    ns (TopLevel (Newtype PName) -> Newtype PName
    forall a. TopLevel a -> a
    tlValue TopLevel (Newtype PName)
    d))
          DParamDecl {}    -> BuildNamingEnv
    forall a. Monoid a => a
    mempty
          Include Located String
    _        -> BuildNamingEnv
    forall a. Monoid a => a
    mempty
          DImport {}       -> BuildNamingEnv
    forall a. Monoid a => a
    mempty -- see 'openLoop' in the renamer
          DModule TopLevel (NestedModule PName)
    m        -> InModule (NestedModule PName) -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv (Maybe ModPath
    -> NestedModule PName -> InModule (NestedModule PName)
    forall a. Maybe ModPath -> a -> InModule a
    InModule Maybe ModPath
    ns (TopLevel (NestedModule PName) -> NestedModule PName
    forall a. TopLevel a -> a
    tlValue TopLevel (NestedModule PName)
    m))
          DModParam {}     -> BuildNamingEnv
    forall a. Monoid a => a
    mempty -- shouldn't happen
          DInterfaceConstraint {} -> BuildNamingEnv
    forall a. Monoid a => a
    mempty
            -- handled in the renamer as we need to resolve
            -- the signature name first (similar to import)

    instance BindsNames (InModule (NestedModule PName)) where
      namingEnv :: InModule (NestedModule PName) -> BuildNamingEnv
    namingEnv (InModule ~(Just ModPath
    m) (NestedModule ModuleG PName PName
    mdef)) = SupplyT Id NamingEnv -> BuildNamingEnv
    BuildNamingEnv (SupplyT Id NamingEnv -> BuildNamingEnv)
    -> SupplyT Id NamingEnv -> BuildNamingEnv
    forall a b. (a -> b) -> a -> b
    $
        do let pnmame :: Located PName
    pnmame = ModuleG PName PName -> Located PName
    forall mname name. ModuleG mname name -> Located mname
    mName ModuleG PName PName
    mdef
           Name
    nm   <- Namespace
    -> ModPath -> PName -> Maybe Fixity -> Range -> SupplyT Id Name
    forall (m :: * -> *).
    FreshM m =>
    Namespace -> ModPath -> PName -> Maybe Fixity -> Range -> m Name
    newTop Namespace
    NSModule ModPath
    m (Located PName -> PName
    forall a. Located a -> a
    thing Located PName
    pnmame) Maybe Fixity
    forall a. Maybe a
    Nothing (Located PName -> Range
    forall a. Located a -> Range
    srcRange Located PName
    pnmame)
           NamingEnv -> SupplyT Id NamingEnv
    forall a. a -> SupplyT Id a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Namespace -> PName -> Name -> NamingEnv
    singletonNS Namespace
    NSModule (Located PName -> PName
    forall a. Located a -> a
    thing Located PName
    pnmame) Name
    nm)

    instance BindsNames (InModule (PrimType PName)) where
      namingEnv :: InModule (PrimType PName) -> BuildNamingEnv
    namingEnv (InModule ~(Just ModPath
    m) PrimType { Maybe Fixity
    ([TParam PName], [Prop PName])
    Located PName
    Located Kind
    primTName :: Located PName
    primTKind :: Located Kind
    primTCts :: ([TParam PName], [Prop PName])
    primTFixity :: Maybe Fixity
    primTName :: forall name. PrimType name -> Located name
    primTKind :: forall name. PrimType name -> Located Kind
    primTCts :: forall name. PrimType name -> ([TParam name], [Prop name])
    primTFixity :: forall name. PrimType name -> Maybe Fixity
    .. }) =
        SupplyT Id NamingEnv -> BuildNamingEnv
    BuildNamingEnv (SupplyT Id NamingEnv -> BuildNamingEnv)
    -> SupplyT Id NamingEnv -> BuildNamingEnv
    forall a b. (a -> b) -> a -> b
    $
          do let Located { Range
    PName
    thing :: forall a. Located a -> a
    srcRange :: forall a. Located a -> Range
    srcRange :: Range
    thing :: PName
    .. } = Located PName
    primTName
             Name
    nm <- Namespace
    -> ModPath -> PName -> Maybe Fixity -> Range -> SupplyT Id Name
    forall (m :: * -> *).
    FreshM m =>
    Namespace -> ModPath -> PName -> Maybe Fixity -> Range -> m Name
    newTop Namespace
    NSType ModPath
    m PName
    thing Maybe Fixity
    primTFixity Range
    srcRange
             NamingEnv -> SupplyT Id NamingEnv
    forall a. a -> SupplyT Id a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Namespace -> PName -> Name -> NamingEnv
    singletonNS Namespace
    NSType PName
    thing Name
    nm)

    instance BindsNames (InModule (ParameterFun PName)) where
      namingEnv :: InModule (ParameterFun PName) -> BuildNamingEnv
    namingEnv (InModule ~(Just ModPath
    ns) ParameterFun { Maybe Text
    Maybe Fixity
    Located PName
    Schema PName
    pfName :: Located PName
    pfSchema :: Schema PName
    pfDoc :: Maybe Text
    pfFixity :: Maybe Fixity
    pfName :: forall name. ParameterFun name -> Located name
    pfSchema :: forall name. ParameterFun name -> Schema name
    pfDoc :: forall name. ParameterFun name -> Maybe Text
    pfFixity :: forall name. ParameterFun name -> Maybe Fixity
    .. }) = SupplyT Id NamingEnv -> BuildNamingEnv
    BuildNamingEnv (SupplyT Id NamingEnv -> BuildNamingEnv)
    -> SupplyT Id NamingEnv -> BuildNamingEnv
    forall a b. (a -> b) -> a -> b
    $
        do let Located { Range
    PName
    thing :: forall a. Located a -> a
    srcRange :: forall a. Located a -> Range
    srcRange :: Range
    thing :: PName
    .. } = Located PName
    pfName
           Name
    ntName <- Namespace
    -> ModPath -> PName -> Maybe Fixity -> Range -> SupplyT Id Name
    forall (m :: * -> *).
    FreshM m =>
    Namespace -> ModPath -> PName -> Maybe Fixity -> Range -> m Name
    newTop Namespace
    NSValue ModPath
    ns PName
    thing Maybe Fixity
    pfFixity Range
    srcRange
           NamingEnv -> SupplyT Id NamingEnv
    forall a. a -> SupplyT Id a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Namespace -> PName -> Name -> NamingEnv
    singletonNS Namespace
    NSValue PName
    thing Name
    ntName)

    instance BindsNames (InModule (ParameterType PName)) where
      namingEnv :: InModule (ParameterType PName) -> BuildNamingEnv
    namingEnv (InModule ~(Just ModPath
    ns) ParameterType { Int
    Maybe Text
    Maybe Fixity
    Located PName
    Kind
    ptName :: Located PName
    ptKind :: Kind
    ptDoc :: Maybe Text
    ptFixity :: Maybe Fixity
    ptNumber :: Int
    ptName :: forall name. ParameterType name -> Located name
    ptKind :: forall name. ParameterType name -> Kind
    ptDoc :: forall name. ParameterType name -> Maybe Text
    ptFixity :: forall name. ParameterType name -> Maybe Fixity
    ptNumber :: forall name. ParameterType name -> Int
    .. }) = SupplyT Id NamingEnv -> BuildNamingEnv
    BuildNamingEnv (SupplyT Id NamingEnv -> BuildNamingEnv)
    -> SupplyT Id NamingEnv -> BuildNamingEnv
    forall a b. (a -> b) -> a -> b
    $
        -- XXX: we don't seem to have a fixity environment at the type level
        do let Located { Range
    PName
    thing :: forall a. Located a -> a
    srcRange :: forall a. Located a -> Range
    srcRange :: Range
    thing :: PName
    .. } = Located PName
    ptName
           Name
    ntName <- Namespace
    -> ModPath -> PName -> Maybe Fixity -> Range -> SupplyT Id Name
    forall (m :: * -> *).
    FreshM m =>
    Namespace -> ModPath -> PName -> Maybe Fixity -> Range -> m Name
    newTop Namespace
    NSType ModPath
    ns PName
    thing Maybe Fixity
    forall a. Maybe a
    Nothing Range
    srcRange
           NamingEnv -> SupplyT Id NamingEnv
    forall a. a -> SupplyT Id a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Namespace -> PName -> Name -> NamingEnv
    singletonNS Namespace
    NSType PName
    thing Name
    ntName)

    instance BindsNames (InModule (Newtype PName)) where
      namingEnv :: InModule (Newtype PName) -> BuildNamingEnv
    namingEnv (InModule ~(Just ModPath
    ns) Newtype { [TParam PName]
    Located PName
    PName
    Rec (Type PName)
    nName :: Located PName
    nParams :: [TParam PName]
    nConName :: PName
    nBody :: Rec (Type PName)
    nName :: forall name. Newtype name -> Located name
    nParams :: forall name. Newtype name -> [TParam name]
    nConName :: forall name. Newtype name -> name
    nBody :: forall name. Newtype name -> Rec (Type name)
    .. }) = SupplyT Id NamingEnv -> BuildNamingEnv
    BuildNamingEnv (SupplyT Id NamingEnv -> BuildNamingEnv)
    -> SupplyT Id NamingEnv -> BuildNamingEnv
    forall a b. (a -> b) -> a -> b
    $
        do let Located { Range
    PName
    thing :: forall a. Located a -> a
    srcRange :: forall a. Located a -> Range
    srcRange :: Range
    thing :: PName
    .. } = Located PName
    nName
           Name
    ntName    <- Namespace
    -> ModPath -> PName -> Maybe Fixity -> Range -> SupplyT Id Name
    forall (m :: * -> *).
    FreshM m =>
    Namespace -> ModPath -> PName -> Maybe Fixity -> Range -> m Name
    newTop Namespace
    NSType  ModPath
    ns PName
    thing Maybe Fixity
    forall a. Maybe a
    Nothing Range
    srcRange
           Name
    ntConName <- Namespace
    -> ModPath -> PName -> Maybe Fixity -> Range -> SupplyT Id Name
    forall (m :: * -> *).
    FreshM m =>
    Namespace -> ModPath -> PName -> Maybe Fixity -> Range -> m Name
    newTop Namespace
    NSValue ModPath
    ns PName
    thing Maybe Fixity
    forall a. Maybe a
    Nothing Range
    srcRange
           NamingEnv -> SupplyT Id NamingEnv
    forall a. a -> SupplyT Id a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Namespace -> PName -> Name -> NamingEnv
    singletonNS Namespace
    NSType PName
    thing Name
    ntName NamingEnv -> NamingEnv -> NamingEnv
    forall a. Monoid a => a -> a -> a
    `mappend`
                   Namespace -> PName -> Name -> NamingEnv
    singletonNS Namespace
    NSValue PName
    thing Name
    ntConName)

    -- | The naming environment for a single declaration.
    instance BindsNames (InModule (Decl PName)) where
      namingEnv :: InModule (Decl PName) -> BuildNamingEnv
    namingEnv (InModule Maybe ModPath
    pfx Decl PName
    d) = case Decl PName
    d of
        DBind Bind PName
    b                 -> InModule (Bind PName) -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv (Maybe ModPath -> Bind PName -> InModule (Bind PName)
    forall a. Maybe ModPath -> a -> InModule a
    InModule Maybe ModPath
    pfx Bind PName
    b)
        DSignature [Located PName]
    ns Schema PName
    _sig      -> (Located PName -> BuildNamingEnv)
    -> [Located PName] -> BuildNamingEnv
    forall m a. Monoid m => (a -> m) -> [a] -> m
    forall (t :: * -> *) m a.
    (Foldable t, Monoid m) =>
    (a -> m) -> t a -> m
    foldMap Located PName -> BuildNamingEnv
    qualBind [Located PName]
    ns
        DPragma [Located PName]
    ns Pragma
    _p           -> (Located PName -> BuildNamingEnv)
    -> [Located PName] -> BuildNamingEnv
    forall m a. Monoid m => (a -> m) -> [a] -> m
    forall (t :: * -> *) m a.
    (Foldable t, Monoid m) =>
    (a -> m) -> t a -> m
    foldMap Located PName -> BuildNamingEnv
    qualBind [Located PName]
    ns
        DType TySyn PName
    syn               -> Located PName -> Maybe Fixity -> BuildNamingEnv
    qualType (TySyn PName -> Located PName
    forall name. TySyn name -> Located name
    tsName TySyn PName
    syn) (TySyn PName -> Maybe Fixity
    forall name. TySyn name -> Maybe Fixity
    tsFixity TySyn PName
    syn)
        DProp PropSyn PName
    syn               -> Located PName -> Maybe Fixity -> BuildNamingEnv
    qualType (PropSyn PName -> Located PName
    forall name. PropSyn name -> Located name
    psName PropSyn PName
    syn) (PropSyn PName -> Maybe Fixity
    forall name. PropSyn name -> Maybe Fixity
    psFixity PropSyn PName
    syn)
        DLocated Decl PName
    d' Range
    _           -> InModule (Decl PName) -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv (Maybe ModPath -> Decl PName -> InModule (Decl PName)
    forall a. Maybe ModPath -> a -> InModule a
    InModule Maybe ModPath
    pfx Decl PName
    d')
        DRec {}                 -> String -> [String] -> BuildNamingEnv
    forall a. HasCallStack => String -> [String] -> a
    panic String
    "namingEnv" [ String
    "DRec" ]
        DPatBind Pattern PName
    _pat Expr PName
    _e        -> String -> [String] -> BuildNamingEnv
    forall a. HasCallStack => String -> [String] -> a
    panic String
    "namingEnv" [String
    "Unexpected pattern binding"]
        DFixity{}               -> String -> [String] -> BuildNamingEnv
    forall a. HasCallStack => String -> [String] -> a
    panic String
    "namingEnv" [String
    "Unexpected fixity declaration"]

        where

        mkName :: Namespace -> Located PName -> Maybe Fixity -> m Name
    mkName Namespace
    ns Located PName
    ln Maybe Fixity
    fx = case Maybe ModPath
    pfx of
                            Just ModPath
    m  -> Namespace -> ModPath -> PName -> Maybe Fixity -> Range -> m Name
    forall (m :: * -> *).
    FreshM m =>
    Namespace -> ModPath -> PName -> Maybe Fixity -> Range -> m Name
    newTop Namespace
    ns ModPath
    m (Located PName -> PName
    forall a. Located a -> a
    thing Located PName
    ln) Maybe Fixity
    fx (Located PName -> Range
    forall a. Located a -> Range
    srcRange Located PName
    ln)
                            Maybe ModPath
    Nothing -> Namespace -> PName -> Range -> m Name
    forall (m :: * -> *).
    FreshM m =>
    Namespace -> PName -> Range -> m Name
    newLocal Namespace
    ns (Located PName -> PName
    forall a. Located a -> a
    thing Located PName
    ln) (Located PName -> Range
    forall a. Located a -> Range
    srcRange Located PName
    ln)

        qualBind :: Located PName -> BuildNamingEnv
    qualBind Located PName
    ln = SupplyT Id NamingEnv -> BuildNamingEnv
    BuildNamingEnv (SupplyT Id NamingEnv -> BuildNamingEnv)
    -> SupplyT Id NamingEnv -> BuildNamingEnv
    forall a b. (a -> b) -> a -> b
    $
          do Name
    n <- Namespace -> Located PName -> Maybe Fixity -> SupplyT Id Name
    forall {m :: * -> *}.
    FreshM m =>
    Namespace -> Located PName -> Maybe Fixity -> m Name
    mkName Namespace
    NSValue Located PName
    ln Maybe Fixity
    forall a. Maybe a
    Nothing
             NamingEnv -> SupplyT Id NamingEnv
    forall a. a -> SupplyT Id a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Namespace -> PName -> Name -> NamingEnv
    singletonNS Namespace
    NSValue (Located PName -> PName
    forall a. Located a -> a
    thing Located PName
    ln) Name
    n)

        qualType :: Located PName -> Maybe Fixity -> BuildNamingEnv
    qualType Located PName
    ln Maybe Fixity
    f = SupplyT Id NamingEnv -> BuildNamingEnv
    BuildNamingEnv (SupplyT Id NamingEnv -> BuildNamingEnv)
    -> SupplyT Id NamingEnv -> BuildNamingEnv
    forall a b. (a -> b) -> a -> b
    $
          do Name
    n <- Namespace -> Located PName -> Maybe Fixity -> SupplyT Id Name
    forall {m :: * -> *}.
    FreshM m =>
    Namespace -> Located PName -> Maybe Fixity -> m Name
    mkName Namespace
    NSType Located PName
    ln Maybe Fixity
    f
             NamingEnv -> SupplyT Id NamingEnv
    forall a. a -> SupplyT Id a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Namespace -> PName -> Name -> NamingEnv
    singletonNS Namespace
    NSType (Located PName -> PName
    forall a. Located a -> a
    thing Located PName
    ln) Name
    n)

    instance BindsNames (InModule (SigDecl PName)) where
      namingEnv :: InModule (SigDecl PName) -> BuildNamingEnv
    namingEnv (InModule Maybe ModPath
    m SigDecl PName
    d) =
        case SigDecl PName
    d of
          SigTySyn TySyn PName
    ts Maybe Text
    _    -> InModule (Decl PName) -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv (Maybe ModPath -> Decl PName -> InModule (Decl PName)
    forall a. Maybe ModPath -> a -> InModule a
    InModule Maybe ModPath
    m (TySyn PName -> Decl PName
    forall name. TySyn name -> Decl name
    DType TySyn PName
    ts))
          SigPropSyn PropSyn PName
    ps Maybe Text
    _  -> InModule (Decl PName) -> BuildNamingEnv
    forall a. BindsNames a => a -> BuildNamingEnv
    namingEnv (Maybe ModPath -> Decl PName -> InModule (Decl PName)
    forall a. Maybe ModPath -> a -> InModule a
    InModule Maybe ModPath
    m (PropSyn PName -> Decl PName
    forall name. PropSyn name -> Decl name
    DProp PropSyn PName
    ps))

    --------------------------------------------------------------------------------
    -- Helpers

    newTop ::
      FreshM m => Namespace -> ModPath -> PName -> Maybe Fixity -> Range -> m Name
    newTop :: forall (m :: * -> *).
    FreshM m =>
    Namespace -> ModPath -> PName -> Maybe Fixity -> Range -> m Name
    newTop Namespace
    ns ModPath
    m PName
    thing Maybe Fixity
    fx Range
    rng =
      (Supply -> (Name, Supply)) -> m Name
    forall a. (Supply -> (a, Supply)) -> m a
    forall (m :: * -> *) a. FreshM m => (Supply -> (a, Supply)) -> m a
    liftSupply (Namespace
    -> ModPath
    -> NameSource
    -> Ident
    -> Maybe Fixity
    -> Range
    -> Supply
    -> (Name, Supply)
    mkDeclared Namespace
    ns ModPath
    m NameSource
    src (PName -> Ident
    getIdent PName
    thing) Maybe Fixity
    fx Range
    rng)
      where src :: NameSource
    src = if PName -> Bool
    isGeneratedName PName
    thing then NameSource
    SystemName else NameSource
    UserName

    newLocal :: FreshM m => Namespace -> PName -> Range -> m Name
    newLocal :: forall (m :: * -> *).
    FreshM m =>
    Namespace -> PName -> Range -> m Name
    newLocal Namespace
    ns PName
    thing Range
    rng = (Supply -> (Name, Supply)) -> m Name
    forall a. (Supply -> (a, Supply)) -> m a
    forall (m :: * -> *) a. FreshM m => (Supply -> (a, Supply)) -> m a
    liftSupply (Namespace -> Ident -> Range -> Supply -> (Name, Supply)
    mkLocal Namespace
    ns (PName -> Ident
    getIdent PName
    thing) Range
    rng)

    -- | Given a name in a signature, make a name for the parameter corresponding
    -- to the signature.
    newModParam :: FreshM m => ModPath -> Ident -> Range -> Name -> m Name
    newModParam :: forall (m :: * -> *).
    FreshM m =>
    ModPath -> Ident -> Range -> Name -> m Name
    newModParam ModPath
    m Ident
    i Range
    rng Name
    n = (Supply -> (Name, Supply)) -> m Name
    forall a. (Supply -> (a, Supply)) -> m a
    forall (m :: * -> *) a. FreshM m => (Supply -> (a, Supply)) -> m a
    liftSupply (ModPath -> Ident -> Range -> Name -> Supply -> (Name, Supply)
    mkModParam ModPath
    m Ident
    i Range
    rng Name
    n)

    {- | Do something in the context of a module.
    If `Nothing` than we are working with a local declaration.
    Otherwise we are at the top-level of the given module.

    By wrapping types with this, we can pass the module path
    to methods that need the extra information. -}
    data InModule a = InModule (Maybe ModPath) a
                      deriving ((forall a b. (a -> b) -> InModule a -> InModule b)
    -> (forall a b. a -> InModule b -> InModule a) -> Functor InModule
    forall a b. a -> InModule b -> InModule a
    forall a b. (a -> b) -> InModule a -> InModule b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall a b. (a -> b) -> InModule a -> InModule b
    fmap :: forall a b. (a -> b) -> InModule a -> InModule b
    $c<$ :: forall a b. a -> InModule b -> InModule a
    <$ :: forall a b. a -> InModule b -> InModule a
    Functor,Functor InModule
    Foldable InModule
    Functor InModule
    -> Foldable InModule
    -> (forall (f :: * -> *) a b.
        Applicative f =>
        (a -> f b) -> InModule a -> f (InModule b))
    -> (forall (f :: * -> *) a.
        Applicative f =>
        InModule (f a) -> f (InModule a))
    -> (forall (m :: * -> *) a b.
        Monad m =>
        (a -> m b) -> InModule a -> m (InModule b))
    -> (forall (m :: * -> *) a.
        Monad m =>
        InModule (m a) -> m (InModule a))
    -> Traversable InModule
    forall (t :: * -> *).
    Functor t
    -> Foldable t
    -> (forall (f :: * -> *) a b.
        Applicative f =>
        (a -> f b) -> t a -> f (t b))
    -> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
    -> (forall (m :: * -> *) a b.
        Monad m =>
        (a -> m b) -> t a -> m (t b))
    -> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
    -> Traversable t
    forall (m :: * -> *) a. Monad m => InModule (m a) -> m (InModule a)
    forall (f :: * -> *) a.
    Applicative f =>
    InModule (f a) -> f (InModule a)
    forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> InModule a -> m (InModule b)
    forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> InModule a -> f (InModule b)
    $ctraverse :: forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> InModule a -> f (InModule b)
    traverse :: forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> InModule a -> f (InModule b)
    $csequenceA :: forall (f :: * -> *) a.
    Applicative f =>
    InModule (f a) -> f (InModule a)
    sequenceA :: forall (f :: * -> *) a.
    Applicative f =>
    InModule (f a) -> f (InModule a)
    $cmapM :: forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> InModule a -> m (InModule b)
    mapM :: forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> InModule a -> m (InModule b)
    $csequence :: forall (m :: * -> *) a. Monad m => InModule (m a) -> m (InModule a)
    sequence :: forall (m :: * -> *) a. Monad m => InModule (m a) -> m (InModule a)
    Traversable,(forall m. Monoid m => InModule m -> m)
    -> (forall m a. Monoid m => (a -> m) -> InModule a -> m)
    -> (forall m a. Monoid m => (a -> m) -> InModule a -> m)
    -> (forall a b. (a -> b -> b) -> b -> InModule a -> b)
    -> (forall a b. (a -> b -> b) -> b -> InModule a -> b)
    -> (forall b a. (b -> a -> b) -> b -> InModule a -> b)
    -> (forall b a. (b -> a -> b) -> b -> InModule a -> b)
    -> (forall a. (a -> a -> a) -> InModule a -> a)
    -> (forall a. (a -> a -> a) -> InModule a -> a)
    -> (forall a. InModule a -> [a])
    -> (forall a. InModule a -> Bool)
    -> (forall a. InModule a -> Int)
    -> (forall a. Eq a => a -> InModule a -> Bool)
    -> (forall a. Ord a => InModule a -> a)
    -> (forall a. Ord a => InModule a -> a)
    -> (forall a. Num a => InModule a -> a)
    -> (forall a. Num a => InModule a -> a)
    -> Foldable InModule
    forall a. Eq a => a -> InModule a -> Bool
    forall a. Num a => InModule a -> a
    forall a. Ord a => InModule a -> a
    forall m. Monoid m => InModule m -> m
    forall a. InModule a -> Bool
    forall a. InModule a -> Int
    forall a. InModule a -> [a]
    forall a. (a -> a -> a) -> InModule a -> a
    forall m a. Monoid m => (a -> m) -> InModule a -> m
    forall b a. (b -> a -> b) -> b -> InModule a -> b
    forall a b. (a -> b -> b) -> b -> InModule a -> b
    forall (t :: * -> *).
    (forall m. Monoid m => t m -> m)
    -> (forall m a. Monoid m => (a -> m) -> t a -> m)
    -> (forall m a. Monoid m => (a -> m) -> t a -> m)
    -> (forall a b. (a -> b -> b) -> b -> t a -> b)
    -> (forall a b. (a -> b -> b) -> b -> t a -> b)
    -> (forall b a. (b -> a -> b) -> b -> t a -> b)
    -> (forall b a. (b -> a -> b) -> b -> t a -> b)
    -> (forall a. (a -> a -> a) -> t a -> a)
    -> (forall a. (a -> a -> a) -> t a -> a)
    -> (forall a. t a -> [a])
    -> (forall a. t a -> Bool)
    -> (forall a. t a -> Int)
    -> (forall a. Eq a => a -> t a -> Bool)
    -> (forall a. Ord a => t a -> a)
    -> (forall a. Ord a => t a -> a)
    -> (forall a. Num a => t a -> a)
    -> (forall a. Num a => t a -> a)
    -> Foldable t
    $cfold :: forall m. Monoid m => InModule m -> m
    fold :: forall m. Monoid m => InModule m -> m
    $cfoldMap :: forall m a. Monoid m => (a -> m) -> InModule a -> m
    foldMap :: forall m a. Monoid m => (a -> m) -> InModule a -> m
    $cfoldMap' :: forall m a. Monoid m => (a -> m) -> InModule a -> m
    foldMap' :: forall m a. Monoid m => (a -> m) -> InModule a -> m
    $cfoldr :: forall a b. (a -> b -> b) -> b -> InModule a -> b
    foldr :: forall a b. (a -> b -> b) -> b -> InModule a -> b
    $cfoldr' :: forall a b. (a -> b -> b) -> b -> InModule a -> b
    foldr' :: forall a b. (a -> b -> b) -> b -> InModule a -> b
    $cfoldl :: forall b a. (b -> a -> b) -> b -> InModule a -> b
    foldl :: forall b a. (b -> a -> b) -> b -> InModule a -> b
    $cfoldl' :: forall b a. (b -> a -> b) -> b -> InModule a -> b
    foldl' :: forall b a. (b -> a -> b) -> b -> InModule a -> b
    $cfoldr1 :: forall a. (a -> a -> a) -> InModule a -> a
    foldr1 :: forall a. (a -> a -> a) -> InModule a -> a
    $cfoldl1 :: forall a. (a -> a -> a) -> InModule a -> a
    foldl1 :: forall a. (a -> a -> a) -> InModule a -> a
    $ctoList :: forall a. InModule a -> [a]
    toList :: forall a. InModule a -> [a]
    $cnull :: forall a. InModule a -> Bool
    null :: forall a. InModule a -> Bool
    $clength :: forall a. InModule a -> Int
    length :: forall a. InModule a -> Int
    $celem :: forall a. Eq a => a -> InModule a -> Bool
    elem :: forall a. Eq a => a -> InModule a -> Bool
    $cmaximum :: forall a. Ord a => InModule a -> a
    maximum :: forall a. Ord a => InModule a -> a
    $cminimum :: forall a. Ord a => InModule a -> a
    minimum :: forall a. Ord a => InModule a -> a
    $csum :: forall a. Num a => InModule a -> a
    sum :: forall a. Num a => InModule a -> a
    $cproduct :: forall a. Num a => InModule a -> a
    product :: forall a. Num a => InModule a -> a
    Foldable,Int -> InModule a -> ShowS
    [InModule a] -> ShowS
    InModule a -> String
    (Int -> InModule a -> ShowS)
    -> (InModule a -> String)
    -> ([InModule a] -> ShowS)
    -> Show (InModule a)
    forall a. Show a => Int -> InModule a -> ShowS
    forall a. Show a => [InModule a] -> ShowS
    forall a. Show a => InModule a -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: forall a. Show a => Int -> InModule a -> ShowS
    showsPrec :: Int -> InModule a -> ShowS
    $cshow :: forall a. Show a => InModule a -> String
    show :: InModule a -> String
    $cshowList :: forall a. Show a => [InModule a] -> ShowS
    showList :: [InModule a] -> ShowS
    Show)