Haskell-导出数据构造函数 [英] Haskell - Export data constructor

查看:69
本文介绍了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 ?

推荐答案

您的某些困惑来自与您要导出的构造函数具有相同的模块名称.

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

应该是

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

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


您当前的导出语句说,在Module Forumla中,导出在Module Formula中定义的Type Formula和函数solve(即在模块作用域内,无论定义在何处))


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

这篇关于Haskell-导出数据构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆