idris - idris 中的纯关键字是否有特定的语法?
问题描述
我正在开发一个函数来读取用户输入的列表,然后从中创建一棵树。这是代码
readList : IO (Maybe BSTree a)
readList = do x <- getLine
if all isDigit (unpack input)
then do (_ ** xs) <- readList
pure ( listToTree (cast x)::xs )
else pure Nothing
这是 listToTree 的类型定义
listToTree : Ord a => List a -> BSTree a
pure ( listToTree (cast x)::xs )
在对 readList 进行类型检查时,我在该行中收到“unexpected pure”错误。这是缩进问题吗?为什么不把纯关键字带到这里?
解决方案
使用 Idris 和类似语言工作时,缩进非常重要。我建议阅读一些标准库代码以了解缩进使用的约定。
以下将解析:
readList : IO (Maybe (BSTree a))
readList = do
x <- getLine
if all isDigit (unpack input)
then do
(_ ** xs) <- readList
pure (listToTree (cast x) :: xs)
else
pure Nothing
推荐阅读
- javascript - 如何在 Rails / HTML 中打印页面?
- python - Python - 替换模块中的特定文件
- javascript - 修改 ImageData 时画布看起来被拉伸
- python - 为什么这个程序给我一个 IndexError: list index out of range 错误但只是有时
- javascript - 当我使用 createElement 并设置它的文本时,我在“查看源”上看不到它
- mysql - 如何在cnf文件中更改mysql中的端口
- ffmpeg - 使用 ffmpeg 解码的文件与使用 flac.exe 解码的文件具有不同的 CRC
- javascript - 将类组件转换为功能组件时出错
- regex - 正则表达式:可选的重复字符
- mysql - SQL Server Migration Assistant for MySQL(中文显示错误)