在我的Elm程序中,我想在一个模块中定义一个类型:
MyModule.elm:
module MyModule exposing (MyType)
type MyType = Constr1 String | Constr2 Int并在另一个模块中构造此类型的值:
Main.elm:
import MyModule exposing (MyType)
import Html exposing (text)
main =
let x = Constr1 "foo" in
text "hello"当我用:
elm-package install elm-lang/html && elm-make Main.elm我得到:
NAMING ERROR ------------------------------------------------------- Main.elm
Cannot find variable `Constr1`
6| let x = Constr1 "foo" in
^^^^^^^
Detected errors in 1 module. 如果我在两个(..)子句中都使用了exposing,这将编译得很好,但我想知道如何表示我想公开构造函数。
附带说明:我还想知道在文档中应该在哪里找到这个。
发布于 2016-05-24 14:07:12
您可以指定像这样公开哪些构造函数:
module MyModule exposing (MyType(Constr1, Constr2))所有类型的构造函数都可以使用(..)表示法公开:
module MyModule exposing (MyType(..))如果您不想公开任何构造函数(意味着您有其他公开的函数来创建您的类型的值),您只需要指定以下类型:
module MyModule exposing (MyType, otherFunctions)在榆树-社区.github.io/elm-常见问题上有关于这个主题的社区文档
https://stackoverflow.com/questions/37415795
复制相似问题