我正在尝试使用这里提供的矢量类型实现一种光线数据类型:http://www.haskell.org/haskellwiki/Numeric_Haskell:_A_Vector_Tutorial#Importing_the_library
Vector只能容纳doubles,所以我想使用Vector类型的Unboxed版本。
下面是我正在尝试编译的代码:
module Main where
import qualified Data.Vector.Unboxed as Vector
data Ray = Ray Data.Vector.Unboxed Data.Vector.Unboxed我得到的错误是
Not in scope: type constructor or class `Data.Vector.Unboxed'
Failed, modules loaded: none.发布于 2012-06-11 02:34:57
模块Data.Vector.Unboxed导出一个类型构造函数Vector,该函数以您想要存储的类型作为参数。由于您也将此模块重命名为Vector,因此此类型的限定名称为Vector.Vector。假设你想要两个双精度的向量,因此你应该这样使用它:
data Ray = Ray (Vector.Vector Double) (Vector.Vector Double)发布于 2012-06-11 02:38:02
通常,当你导入一些东西时,你会这样做:
import Data.Foo -- A module that contains "data Bar = Bar ..."
myfunction = Bar 3 2 4 -- Use Bar如您所见,您可以直接访问Data.Foo模块中的所有内容,就像在同一个模块中编写代码一样。
相反,您可以使用限定导入某些内容,这意味着您必须在每次访问时指定指向您引用的内容的完整模块“路径”:
import qualified Data.Foo -- A module that contains "data Bar = Bar ..."
myfunction = Data.Foo.Bar 3 2 4 -- Use Bar在这里,您必须指定要访问的数据类型的完整“路径”,因为该模块已作为限定导入。
还有另一种方法可以导入带有限定的内容;您可以为模块"path“指定别名,如下所示:
import qualified Data.Foo as Foo -- A module that contains "data Bar = Bar ..."
myfunction = Foo.Bar 3 2 4 -- Use Bar我们已将Data.Foo部件重命名为简单的Foo。这样,我们就可以在引用数据构造函数时编写Foo.Bar。
您导入了别名为Vector的模块Data.Vector.Unboxed。这意味着当您想要访问Vector数据类型时,必须使用Vector.Vector。我建议你像这样导入向量:
import Data.Vector.Unboxed (Vector)
import qualified Data.Vector.Unboxed as Vector这样,您就可以直接导入Vector类型,这样就可以在没有任何模块限定符的情况下访问它,但是当您想要使用Vector函数时,您需要添加Vector前缀(例如Vector.null ...)。
https://stackoverflow.com/questions/10971232
复制相似问题