小编Wes*_*Wes的帖子

为什么我翻译成Python的Haskell不能正常工作?

哈斯克尔:

average x y = (x + y) / 2

sqrt' :: (Ord a, Fractional a) => a -> Int -> a
sqrt' 0 _ = 0.0
sqrt' 1 _ = 1.0
sqrt' s approximations = (infsqr' s) !! approximations

infsqr' n = unfoldr acc 1 where
    acc guess | guess < 0 = Nothing
              | otherwise = Just (newguess', newguess') where
                newguess' = average guess (n / guess)
Run Code Online (Sandbox Code Playgroud)

蟒蛇:

def unfold(f, x):
    while True:
        w, x = f(x)
        yield …
Run Code Online (Sandbox Code Playgroud)

python math haskell

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

对目录中的文件大小求和

我无法绕过如何实现这一目标.我对使用monads/IO比较陌生,所以如果我错过了一些明显的东西,请原谅.我搜索了谷歌一段时间,没有得到什么,我读过的任何东西都让我弄清楚如何做到这一点.

这就是我现在拥有的:

import System.Path.Glob (glob)
import System.Posix.Files (fileSize, getFileStatus)

dir = "/usr/bin/"
lof = do files <- (glob (dir++"*"))
         (mapM_ fileS files)

fileS file = do fs <- getFileStatus file
                print (fileSize fs)
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,这会得到尺寸并打印出来,但我仍然坚持如何实际求和它们.

io monads haskell

3
推荐指数
1
解决办法
203
查看次数

标签 统计

haskell ×2

io ×1

math ×1

monads ×1

python ×1