小编Cha*_*ase的帖子

树声明之间的区别?

有什么区别

data Tree a = Leaf a | Node (a, Tree a, Tree a) deriving Show
Run Code Online (Sandbox Code Playgroud)

data Tree a = Leaf a | Node a (Tree a) (Tree a) deriving Show
Run Code Online (Sandbox Code Playgroud)

注意:节点的括号

haskell

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

树遍历inorder尾递归

我是否正确使用尾递归实现了顺序级别顺序树横向?

inorder (Leaf n) temp = n:temp
inorder (Node (n, left, right)) temp = inorder left (n:inorder right temp)
inorder :: Tree a -> [a] -> [a]
Run Code Online (Sandbox Code Playgroud)

树被声明为

data Tree a = Leaf a | Node (a, Tree a, Tree a) deriving Show
Run Code Online (Sandbox Code Playgroud)

[2,1,3]在电话inorder three []中返回 three = Node (1, Leaf 2, Leaf 3)

haskell tail-recursion

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

列表中每对的第一个元素

我知道如何获得一对的第一个元素 first (x:_) = x

但是如何获取对列表并返回每个第一项的列表?我是否使用循环或是否有其他语法?

[(1,2),(3,4),(5,6)] gives [1,3,5]
Run Code Online (Sandbox Code Playgroud)

haskell

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

标签 统计

haskell ×3

tail-recursion ×1