haskell

Building a list of all branches in a tree

南楼画角 提交于 2020-08-26 10:03:58
问题 I need to make function returns all possible branches from a tree with this form: data Tree a = EmptyT | NodeT a ( Tree a ) ( Tree a ) deriving (Show) everyBranch :: Tree a -> [[a]] I'm not sure how to approach this... xD I'm still a newbie in Haskell. Let's say that I have: 1 / \ 2 3 /\ / \ 4 5 7 8 I want to get: [[1,2,4], [1,2,5], [1,3,8], [1,3,7]] 回答1: We'll use a recursive approach. Let's start with a rough skeleton: everyBranch :: Tree a -> [[a]] everyBranch EmptyT = _something

Unifying Types in Haskell

自古美人都是妖i 提交于 2020-08-24 10:25:57
问题 I'm kind of stuck with an assignement concerning my exams. I want to find out the types of those two functions by applying the unifying algorithm by hand: map map (\x -> x >>= (\y -> y)) Could someone point me to the right direction? The only ressource I could find until now was the wikipedia entry which is not really aiding me because of the high level of abstraction. Greetings and thank you. 回答1: Let's just do the first. map :: (a -> b) -> [a] -> [b] Now we can write it again with two

Unifying Types in Haskell

末鹿安然 提交于 2020-08-24 10:22:08
问题 I'm kind of stuck with an assignement concerning my exams. I want to find out the types of those two functions by applying the unifying algorithm by hand: map map (\x -> x >>= (\y -> y)) Could someone point me to the right direction? The only ressource I could find until now was the wikipedia entry which is not really aiding me because of the high level of abstraction. Greetings and thank you. 回答1: Let's just do the first. map :: (a -> b) -> [a] -> [b] Now we can write it again with two