【发布时间】:2014-10-07 16:09:44
【问题描述】:
我尝试将计算“a”的 Adler-32 哈希的 Haskell 代码转换为 Frege,但得到的是 6422626 而不是 300286872
摘自 http://book.realworldhaskell.org/read/functional-programming.html 的 Haskell 代码
adler32_try2 xs = helper (1,0) xs
where helper (a,b) (x:xs) =
let a' = (a + (ord x .&. 0xff)) `mod` base
b' = (a' + b) `mod` base
in helper (a',b') xs
helper (a,b) _ = (b `shiftL` 16) .|. a
摘自https://github.com/Dierk/Real_World_Frege/blob/master/realworld/chapter4/G_Reducing.fr的弗雷格代码
adler32 xs = accuAdler (1,0) xs where
accuAdler (a,b) (y:ys) =
let newA = (a + (ord y `band` 0xff)) `mod` base
newB = (newA + b) `mod` base
in accuAdler (newA, newB) ys
accuAdler (a,b) _ = (b `bshl` 16) `bor` a
是运算符选择错误还是有符号/无符号 32/64 整数属性?
【问题讨论】:
-
这是一个我想从 Haskell 移植一段时间的包,因为不同的操作符确实是不必要的混淆。有志愿者吗?
-
我会的,英戈。我正在移植 java.util,但我可以坚持下去,因为我必须做更多的事情才能将其推出。