小编Edw*_*lho的帖子

Haskell to Python:多功能转换问题

我是编程的新手,我被要求将3个haskell函数转换为python作为练习练习.3个功能是连接的,因为一个的输出用作下一个的输入,依此类推.

我得到了haskell函数的功能,但我不知道如何开始转换它们!

这是haskell代码:

factorial :: Int -> Int
factorial n = product (down n)

product :: [Int] -> Int
product [] = 1
product (a:as) = a * product as

down :: Int -> [Int]
down 0 = []
down n = n : down (n-1)
Run Code Online (Sandbox Code Playgroud)

这是我转换它的尝试:

class function:
    def down(self):
        if self.n == 0:
            self.lista = []
        else:
            self.lista = range(self.n, 0, -1)

    def product(self):
        for x in self.lista:
            if x == []:
                self.product = 1
            if x != …
Run Code Online (Sandbox Code Playgroud)

python haskell code-conversion

4
推荐指数
1
解决办法
958
查看次数

Python 中的循环编程(corecursion)-可能吗?

我知道Python有一些惰性实现,因此,我想知道是否可以在Python中使用循环编程。

如果不是,为什么?

python

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

标签 统计

python ×2

code-conversion ×1

haskell ×1