Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell - Export data constructor

Tags:

haskell

I have this data on my Module Formula :

data Formula = Formula {
    typeFormula :: String, 
    nbClauses   :: Int,
    nbVars      :: Int,
    clauses     :: Clauses       
}

And I want to export it but I don't know the right syntax :

module Formula (
    Formula ( Formula ),
    solve
) where

Someone can tell me the right syntax please ?

like image 896
Adrien Varet Avatar asked Dec 21 '17 17:12

Adrien Varet


1 Answers

Some of your confusion is coming from having the same module name as the constructor you're trying to export.

module Formula (
    Formula ( Formula ),
    solve
) where

Should be

module Formula (
    Formula (..),
    solve
) where

Or

module Formula (
    module Formula ( Formula (..)),
    solve
) where

Your current export statement says, in the Module Formula, export the Type Formula defined in the Module Formula and the function solve (that is in scope for the module, wherever it is defined))

The (..) syntax means, export all constructors for the preceding type. In your case, it is equivalent to the explicit

module Formula (
    Formula (typeFormula,nbClauses, nbVars,clauses),
    solve
) where
like image 114
jkeuhlen Avatar answered Oct 16 '22 07:10

jkeuhlen