Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export data family instance constructor

How can I export the constructors of my data family instances? I've tried various ways without success (see commented out code):

module Test (
    --Foo () (..)
    --type Foo () (..)
    --UnitBar
) where

class Foo a where
    data Bar a :: *

instance Foo () where
    data Bar () = UnitBar

The only way I've been able to successfuly export the constructor is when doing a

module Test where

Notice the absense of parentheses. The drawback of this approach is that too much information leaves!

like image 483
Thomas Eding Avatar asked Jan 12 '23 06:01

Thomas Eding


1 Answers

Use

module Test (
    Bar(..)
) where

to export all constructors from the associated data family Bar. Or

module Test (
    Bar(UnitBar)
) where

to only export the single constructor.

You can read the relevant section in GHC's documentation for more details.

like image 139
shang Avatar answered Jan 21 '23 09:01

shang