小编Jam*_*mes的帖子

Haskell数组索引超出范围

我的代码粘贴在这里.下面是我的ghci调试会话.当'len'绑定为90570时,我仍然不明白为什么它的范围为(0,-193459561).

*Main> :break 125
Breakpoint 4 activated at SVMCF.hs:125:13-86
*Main> :trace main
Stopped at SVMCF.hs:125:13-86
_result :: UA.Array Int [User] = _
len :: Int = 90570
rts :: [RTuple] = (1,1,5.0) : (1,2,3.0) : (1,3,4.0) : (1,4,3.0) :
                  (1,5,3.0) : ....
[SVMCF.hs:125:13-86] *Main> :lis
124      points :: A.Array Int [Int]
125      points = assert (len > 0) $ A.listArray (1::Int, len) $ map (\(u,i,r) -> [u,i]) rts
126      values :: UA.UArray Int Double
[SVMCF.hs:125:13-86] *Main> :ste
Stopped …
Run Code Online (Sandbox Code Playgroud)

arrays haskell range

17
推荐指数
1
解决办法
1908
查看次数

parsec中意外的输入结束

我想解析这样的文件:

66:3 3:4
329:2 
101:3 
495:4 
55:5 
268:5 
267:2 
242:4 
262:1 
861:1 

我的代码如下:

getTestData :: String -> IO [[(Int, Int)]]
getTestData name = do
    --res <- parseFromFile testData (name ++ ".test")
    fc <- readFile (name ++ ".test")
    let res = parse testData "test data" fc
    case res of
        Left e -> error $ show e-- "test data parse eror."
        Right ts -> return ts

eol = char '\n'
testData = endBy line eol
--testData = many line
testTuple = do …
Run Code Online (Sandbox Code Playgroud)

haskell parsec

5
推荐指数
1
解决办法
3022
查看次数

标签 统计

haskell ×2

arrays ×1

parsec ×1

range ×1