0

I'd like to put the definition of a top-level Agda module and a local anonymous module using it in the same file. However, the top-level module has parameters, and I'd like to instantiate it in the second module.

So basically I would like to do something like this:

module MyModule (A : Set) where

foo : A -> A
foo x = x

module _ where
  open import Data.Bool
  open MyModule Bool
  
  bar = foo true

However, the open MyModule Bool line fails with "The module MyModule is not parameterized, but is being applied to arguments".

Is there a way to do this without:

  • putting the second module in a separate file

  • indenting the contents of MyModule, i.e. something like

    module _ where
    
    module MyModule (A : Set) where
      foo : A -> A
      foo x = x
    
    module _ where
      open import Data.Bool
      open MyModule Bool
    
      bar = foo true
    

?

Cactus
  • 27,075
  • 9
  • 69
  • 149

1 Answers1

1

The precise thing you're asking for is currently not possible in Agda. The closest thing I can think of is the following:

module MyModule where

module Main (A : Set) where

  foo : A -> A
  foo x = x

private
  module _ where
    open import Data.Bool
    open Main Bool

    bar = foo true

open Main public

This will expose the contents of the main module in their generic form while hiding the private definition bar from other modules. However, when you import the module and want to instantiate the parameter, you cannot write open import MyModule Nat directly, you'd have to instead write

import MyModule using (module Main)
open MyModule.Main Nat

(for importing the generic version, open import MyModule would work just fine).

Jesper
  • 2,781
  • 13
  • 14