6

我对 Haskell 这种语言有些熟悉,但对工具链不太熟悉。(在 cabal 和 stack 存在之前,我曾使用 Haskell。)有人告诉我,stack 是我应该用来管理 Haskell 项目的工具。我正在尝试学习 haste 库,但我在尝试的第一个教程中遇到了困难,因为我无法安装 hplayground。我创建了一个堆栈项目;我的 stack.yaml 有

extra-deps:
- ghc-simple-0.3
- haste-compiler-0.5.3
- shellmate-0.2.3
- haste-perch-0.1.0.9
- hplayground-0.1.3.1

我的 .cabal 文件在 build-depends 中列出了 hplayground。但是当我运行 stack build 时,我得到了这些错误:

Configuring haste-perch-0.1.0.9...
Building haste-perch-0.1.0.9...
Preprocessing library haste-perch-0.1.0.9...

Haste/Perch.hs:17:15: Warning:
    -XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS

Haste/App/Perch.hs:18:15: Warning:
    -XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS
[1 of 2] Compiling Haste.App.Perch  ( Haste/App/Perch.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.4.0/build/Haste/App/Perch.o )

Haste/App/Perch.hs:61:15: Not in scope: ‘newTextElem’

Haste/App/Perch.hs:71:9:
    Not in scope: ‘setAttr’
    Perhaps you meant ‘jsSetAttr’ (imported from Haste.App)

Haste/App/Perch.hs:76:15:
    Not in scope: ‘newElem’
    Perhaps you meant one of these:
    ‘nelem’ (line 75), ‘notElem’ (imported from Prelude)

以及很多类似的错误。对我做错了什么有任何想法吗?

更广泛地说:对于没有使用 Haskell 工具链的人来说,有什么快速、简单的方法可以快速启动和运行?

4

2 回答 2

3

安装完 ghc 和 cabal 后,您需要按如下方式安装 Haste 编译器(来自http://haste-lang.org/downloads/):

$ cabal update
$ cabal install haste-compiler
$ haste-boot

完成此操作后,应该可以使用“hastec”(急速编译器)将 haskell 编译为 javascript。此外,应该可以使用“haste-cabal”(cabal 的 haste 版本)来安装诸如 haste-perch 之类的库,以便在您的程序中使用。

haste-perch 的自述文件 ( https://github.com/agocorona/haste-perch ) 包含安装 haste-perch 的说明。这些说明使用“haste-inst”来安装 haste-perch,但“haste-inst”已过时(并且不再存在)。使用以下修改后的说明安装 haste-perch:

>git clone http://github.com/agocorona/haste-perch.git
>cd haste-perch
>haste-cabal install

我能够安装 haste-perch 并成功构建它附带的示例。

我也尝试构建 hplayground 但遇到编译问题,看起来好像是由于代码没有更新为使用 haste 0.5 。例如,“OnClick”在早期版本的 haste 中是一个有效的标识符,但现在不再是:

src/Haste/HPlay/View.hs:820:45:
    Not in scope: data constructor ‘OnClick’
    Perhaps you meant ‘Click’ (line 1017)
于 2016-03-20T04:34:58.603 回答
3

Haste 的事件 API 在 0.4 和 0.5 系列之间进行了大修,而 HPlayground 仍然在 0.4 上。如果你想使用它,不幸的是你不得不回退到 0.4,直到 HPlayground 被修补为 0.5。

一般来说,如果你在非 Linux 平台上,你应该安装预构建的二进制文件(如果你也在 Linux 平台上,因为你有手册页和其他细节);构建过程可能很棘手并且容易出错。

完成后,您可以参考haste-lang.org 上的文档和资源页面,其中包含指向 API 文档、视频教程、源代码示例等的链接。

于 2016-03-21T09:54:29.437 回答