liveBook · Manning

Export

As explained in Type-Driven Development with Idris

The Idris export modifier makes a declaration's name and type available to importing modules while hiding its definition or data constructors.

An export modifier controls what importing modules can access: a name, its type, its definition, or a data type’s constructors. section 10.3.1

Choose the modifier according to the interface importers need:

  • private hides a declaration from other modules. Declarations without a modifier are private by default. section 10.3.1
  • export exposes a declaration’s name and type, but not its definition; for data types, constructors remain hidden. section 10.3.1
  • public export exposes definitions and data constructors as well as names and types. Use it when other modules need a function’s behavior in a type, such as with type-level functions or type synonyms. section 10.3.1 section 15.2.5
  • Prefer export over exposing a function’s definition unless another module needs that definition. section 15.2.5

Keep a data type abstract

Export Shape but not its constructors, then export functions such as triangle and rectangle to create values. Importing modules can use those functions but cannot pattern-match on Shape. section 10.3.1

module Shape_abs
export                                         #1
data Shape = Triangle Double Double
           | Rectangle Double Double
           | Circle Double
export
triangle : Double -> Double -> Shape           #2
triangle = Triangle
export
rectangle : Double -> Double -> Shape          #2
rectangle = Rectangle
export
circle : Double -> Shape                       #2
circle = Circle

The module listing shows Shape’s constructors kept behind exported creation functions. section 10.3.1

How Type-Driven Development with Idris covers it

How deep it goes
Distinguishes private, type-only export, and public export, including their effects on definitions and data constructors.
Examples
Uses Shape constructors and area calculations, and shows exported interfaces for Process and DataStore.
What it assumes
Introduces module declarations and imports before describing visibility controls.
What you can do after
Configure module visibility by choosing which names, types, definitions, and constructors importing code can access.
How it connects
Connects module imports with abstract data types, type synonyms, and type-level functions.

This explainer was generated by Manning's knowledge graph from the text of Type-Driven Development with Idris. The section links point to the parts of the book it draws on.