Home > Enterprise >  How the re-export a single entity in haskell
How the re-export a single entity in haskell

Time:06-23

How to re-export a single entity in haskell?
I know modules can be re-exported, but is this also possible for a single entity (like a function)?

I've tried this example:
File: SomeData.hs

module SomeData where
data SomeData = SomeData

File: ReExport.hs

module ReExport ( SomeData ) where
import SomeData

File: Main.hs

import ReExport

x = SomeData -- Error on this line: Illegal term-level use of the type constructor ‘SomeData’

The re-export alone compiles with no problems, but when I try to use anything from it I get the error: Illegal term-level use of the type constructor ‘SomeData’. What exactly is ReExport.hs exporting in this case?

CodePudding user response:

What exactly is ReExport.hs exporting in this case?

The type constructor, so you can use SomeData as type:

import ReExport

x :: SomeData
x = undefined

If you defined a type:

data SomeType = SomeData

you are thus exporting SomeType.

If you want to export the data constructor as well, you use:

module ReExport (SomeData(SomeData)) where

import SomeData

and then you can thus use:

import ReExport

x :: SomeData
x = SomeData
  • Related