gpt4 book ai didi

haskell - haskelwiki 教程中的秒差距错误

转载 作者:行者123 更新时间:2023-12-02 10:14:44 24 4
gpt4 key购买 nike

我正在遵循 http://www.haskell.org/haskellwiki/Hitchhikers_guide_to_Haskell 中的代码,并且代码(第 2 章中)给出了错误。教程中没有提到作者姓名/电子邮件,所以我来这里寻求建议。代码如下,错误发生在“eof”这个词上。

module Main where

import Text.ParserCombinators.Parsec

parseInput =
do dirs <- many dirAndSize
eof
return dirs

data Dir = Dir Int String deriving Show

dirAndSize =
do size <- many1 digit
spaces
dir_name <- anyChar `manyTill` newline
return (Dir (read size) dir_name)

main = do
input <- getContents
putStrLn ("Debug: got inputs: " ++ input)

最佳答案

那个教程是很久以前写的,当时秒差距还很简单。如今,从 parsec-3 开始,库可以包装 monad,因此您现在必须指定(或以其他方式消除歧义)在某些时候要使用的类型。这是其中之一,给出 eof 例如表达式类型签名 eof::Parser () 使其编译。

关于haskell - haskelwiki 教程中的秒差距错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8924128/

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