Beginning Haskell - getting “not in scope: data constructor” error

后端 未结 3 1561
半阙折子戏
半阙折子戏 2021-02-05 06:17

I\'m going through the problems in the Haskell O\'Reilly book. The problem I am working on is

Using the binary tree type that we defined earlier in this chapter         


        
3条回答
  •  情深已故
    2021-02-05 06:27

    You pattern-match against constructors, i.e. the cases, of your Tree ADT. Tree is just what sums them all up.

    It's much more straightforward like this, and, most of all, correct:

    height Empty = 0
    height (Node _ l r) = 1 + max (height l) (height r)
    

提交回复
热议问题