gpt4 book ai didi

haskell - 使用 case 时解析输入 '->' 错误

转载 作者:行者123 更新时间:2023-12-02 04:03:05 27 4
gpt4 key购买 nike

我正在通过向你学习 Haskell 来学习 Haskell,但教程中的函数之一似乎无法编译。我不明白为什么,我认为这可能是缩进,但似乎没有什么区别。大多数 SE 问题似乎都涉及 ghci 并尝试设置变量。

describeList :: [a] -> String
describeList xs = "The list is " ++ case xs of [] -> "empty."
[x] -> "a singleton list."
xs -> "a longer list."

我得到的错误是:

describeList.hs:4:95: parse error on input '->'
Failed, modules loaded: none.

最佳答案

原来问题出在我的 VIM 选项卡设置上。事实证明 Haskell 对缩进非常特别。我将 vimrc 文件更改为这些设置。

" Tab specific option
set tabstop=8 "A tab is 8 spaces
set expandtab "Always uses spaces instead of tabs
set softtabstop=4 "Insert 4 spaces when tab is pressed
set shiftwidth=4 "An indent is 4 spaces
set shiftround "Round indent to nearest shiftwidth multiple

来源:http://www.haskell.org/haskellwiki/Vim

关于haskell - 使用 case 时解析输入 '->' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25482896/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com