小编use*_*068的帖子

Haskell推断出太严格的类型

免责声明:我刚开始学习Haskell,我不确定"严格"是否正确.

我试图缩小我的问题,但我真的找不到问题,所以这是我的代码不能编译:

module Json where
import Data.List (intersperse)

data JNode = 
    JObject [(String, JNode)]
  | JArray  [JNode]
  | JString String
  | JNumber Double
  | JBool   Bool
  | JNull

instance Show JNode where
  show = show_node 0 where
    glue = foldl (++) ""
    show_tabs n              = glue $ take n $ repeat "  "
    show_list n              = glue . intersperse ",\n" . map (show_pair (n + 1))
    show_sect n l r xs       = glue ["\n", tabs, l, "\n", show_list …
Run Code Online (Sandbox Code Playgroud)

haskell type-inference

9
推荐指数
2
解决办法
232
查看次数

简单的解析器耗尽内存

我想了解为什么这个简单的解析器用于大文件的内存不足.我真的很无知我做错了什么.

import Data.Attoparsec.ByteString.Char8
import qualified Data.Attoparsec.ByteString.Lazy as Lazy
import System.Environment
import qualified Data.ByteString.Lazy as B
import Control.Applicative

parseLine :: Parser String
parseLine = manyTill' anyChar (endOfLine <|> endOfInput)

parseAll :: Parser [Int]
parseAll = manyTill' 
        (parseLine >> (return 0)) -- discarding what's been read
        endOfInput

main :: IO()
main = do 
        [fn] <- getArgs
        text <- B.readFile fn

        case Lazy.parse parseAll text of
                Lazy.Fail _ _ _ -> putStrLn "bad"
                Lazy.Done _ _ -> putStrLn "ok" 
Run Code Online (Sandbox Code Playgroud)

我正在运行该程序:

 runhaskell.exe test.hs x.log …
Run Code Online (Sandbox Code Playgroud)

haskell memory-leaks attoparsec

7
推荐指数
1
解决办法
163
查看次数