haskell - size of the tree, Not in scope -


here code:

data binary_tree = null                        |node {element :: a, left_tree, right_tree :: binary_tree a}    deriving (show, eq)  --depth_of_tree   dot :: integral b => binary_tree -> b dot null = 0 dot node (a left right) = 1 + (dot node (a left right)) + (dot node (a left right)) 

however, when load in ghci it, , input

dot node (2 (node 3 null null) null) 

it comes out error:

<interactive>:13:1:     not in scope: `dot'     perhaps meant `not' (imported prelude) 

anyone likes tell me what's wrong code pls?

thanks can me advice xd

1) error on declaration (your code contains infinite recursion). try this:

--depth_of_tree  dot :: integral b => binary_tree -> b dot null = 0 dot (node _ left right) = 1 + dot left + dot right 

2) error parentheses. try this

  dot $ node 2 (node 3 null null) null 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -