PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 24, 2022

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

 August 24, 2022     haskell, module     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing