【问题标题】:Importing Newtype(s) from another module从另一个模块导入新类型
【发布时间】:2017-12-06 14:47:26
【问题描述】:

我最近在学习 PureScript,并做了一个在屏幕上绘制立方体的小应用程序。一切都很好,我在Main 模块的顶部定义了几个newtypes,如下所示:

newtype Vec2 = Vec2
    {
        x :: Number
    ,   y :: Number
    }

newtype Vec3 = Vec3
    {
        x :: Number
    ,   y :: Number
    ,   z :: Number
    }

我还有一些功能可以进行转换,例如perspectiveDivide 等,我想移动到另一个模块Transforms 只是为了更好地组织。所以我将这些类型移到了 Transforms 模块中,并导出了它们。

module Transforms (Vec2, Vec3, perspectiveDivide) where

上面的类型都遵循这个。

现在我尝试使用选择性导入功能在主模块中导入这些,但没有成功。

import Transforms (Vec2, Vec3, perspectiveDivide)

但在尝试使用仍在主模块中的函数 projectToScreen 时,它仍然给我一个错误。错误是这样的:

在模块 Main 在 src/Main.purs 第 30 行,第 10 列 - 第 30 行,列 18

Unknown data constructor Vec3

https://github.com/purescript/documentation/blob/master/errors/UnknownName.md 了解更多信息,或提供与此相关的内容 错误。

我既是函数式编程的新手,也是 PureScript 的新手。这个错误是什么意思?

【问题讨论】:

    标签: purescript newtype


    【解决方案1】:

    module Transforms (Vec2, Vec3, perspectiveDivide) where 只导出类型构造函数。

    您还想使用Vec2(..) 来导出数据构造函数。相同的语法适用于导入。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-15
      • 2020-11-15
      • 2015-05-09
      相关资源
      最近更新 更多