使用 cabal 安装后在 haskell 中导入 lib
请原谅这个问题的简单性,但我没有找到另一个可以解决我的问题的问题。我已经安装了 haskell 和 leksah,然后执行“cabal install nat”来安装自然数库。该库看起来像是安装在“/Users/jstanford/Library/Haskell/ghc-7.0.4/lib/nat-0.2/lib”中,
我在 leksah 中创建了一个工作区和一个包,并更新了我的首选项以查看:
/库/框架/GHC.framework /用户/jstanford/库/Haskell /Users/jstanford/.leksah-0.10/packageSources
用于包源,并保留默认的 ~/.leksah-0.10/packageSources 用于解压 cabal 包。
我从“函数式算法设计的珍珠”中获取了第一段代码,所以我的代码如下所示:
-----------------------------------------------------------------------------
--
-- Module : Main
-- Copyright :
-- License : AllRightsReserved
--
-- Maintainer :
-- Stability :
-- Portability :
--
-- |
--
-----------------------------------------------------------------------------
module Main (
main
) where
import Data.List ((\\))
import GHC.Arr (accumArray, elems, Array(..))
minfree :: [Nat] -> Nat
minfree xs = head([0 ..])\\ xs
search :: Array Int Bool -> Int
search = length takeWhile id . elems
checklist :: [Int] -> Array Int Bool
checklist xs = accumArray(V) False (0,n)
(zip (filter (<= n) xs) (repeat True))
where n = length xs
main = (
minfree[0, 2, 5]
)
Leksah 能够找到 \ 和 Array 的导入,但找不到 Nat。有关如何查找导入的任何指示吗?编译器还会抱怨accumArray(V)。我怀疑 V 并不真正应该是大写字母 V,而是一些看起来像 V 的符号。对此的指导也将非常感激!
Excuse the simplicity of this question, but I didn't find another question that addressed my issue. I have installed haskell and leksah, then performed "cabal install nat" to install the natural numbers lib. The lib looks like it was installed in "/Users/jstanford/Library/Haskell/ghc-7.0.4/lib/nat-0.2/lib"
I created a workspace and a package in leksah, and updated my prefs to look in:
/Library/Frameworks/GHC.framework
/Users/jstanford/Library/Haskell
/Users/jstanford/.leksah-0.10/packageSources
for package sources and left the default ~/.leksah-0.10/packageSources for unpacking cabal packages.
I grabbed the first snippets of code from "Pearls of Functional Algorithm Design", so my code looks like this:
-----------------------------------------------------------------------------
--
-- Module : Main
-- Copyright :
-- License : AllRightsReserved
--
-- Maintainer :
-- Stability :
-- Portability :
--
-- |
--
-----------------------------------------------------------------------------
module Main (
main
) where
import Data.List ((\\))
import GHC.Arr (accumArray, elems, Array(..))
minfree :: [Nat] -> Nat
minfree xs = head([0 ..])\\ xs
search :: Array Int Bool -> Int
search = length takeWhile id . elems
checklist :: [Int] -> Array Int Bool
checklist xs = accumArray(V) False (0,n)
(zip (filter (<= n) xs) (repeat True))
where n = length xs
main = (
minfree[0, 2, 5]
)
Leksah was able to find the imports for \ and Array, but can't find Nat. Any pointers on how to find the import? The compiler also complains about accumArray(V). I suspect that V is not really supposed to be the capital letter V, rather some symbol that looks like a V. Guidance on that would be very much appreciated as well!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Nat
类型在Data.Number.Nat
,所以你应该将它导入到文件的顶部:至于
(V)
,它可能意味着成为<代码>(||)。 “V”很可能是 ∨,逻辑或的符号:通常称为布尔或运算符。像这样的运算符替换在排版 Haskell 代码中很常见,但在您习惯看到它们之前可能会很混乱。此外,您不应从 GHC.Arr 导入数组函数;这是一个内部 GHC 模块;我建议导入
Data.Array
代替。
The
Nat
type is defined inData.Number.Nat
, so you should import it at the top of your file:As for the
(V)
, it's probably meant to be(||)
. The "V" is most likely ∨, the symbol for logical disjunction: more commonly known as the boolean or operator. Operator substitutions like this are common in typeset Haskell code, but can be quite confusing until you get used to seeing them.Additionally, you shouldn't import the array functions from
GHC.Arr
; that's an internal GHC module; I recommend importingData.Array
instead.