Haskell - Export data constructor

泪湿孤枕 提交于 2019-12-30 08:26:11

问题


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 ?


回答1:


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 Forumla, 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


来源:https://stackoverflow.com/questions/47929556/haskell-export-data-constructor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!