Wednesday, August 24, 2022

[FIXED] How the re-export a single entity in haskell

Issue

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?


Solution

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


Answered By - Willem Van Onsem
Answer Checked By - Marie Seifert (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.