小编432*_*320的帖子

有没有办法在Haskell中解决不同数量的参数?

您好我想定义plusTree.

对此的定义.

在此输入图像描述

data Tree = Null | Node Int Tree Tree   deriving Show


plusTree :: Tree -> Tree -> Tree
plusTree Null         ys     = Null
plusTree xs          Null    = Null
plusTree (Node x xs) (Node y ys)  = Node (x+y) (plusTree xs ys) 
Run Code Online (Sandbox Code Playgroud)

我创建了上面的代码.

构造函数"Node"应该有3个参数,但是已经给出了2个参数

在模式中:节点x xs

在`plusTree'的等式中:plusTree(Node x xs)(Node y ys)= Node(x + y)(交互式:IHaskell544.plusTree xs ys)

我也遇到了上述错误.所以我尝试了各种方法.我最后虽然在第四个参数中添加一些内容时它会起作用.

plusTree :: Tree -> Tree -> Tree
plusTree Null         ys     = Null
plusTree xs          Null    = Null
plusTree (Node x …
Run Code Online (Sandbox Code Playgroud)

haskell

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

标签 统计

haskell ×1