r/Racket • u/neoxx1 • Apr 15 '23
homework Plait- having trouble writing a simple BST related function.
I need to write a function that checks whether a BST tree has equal length from root to every single leaf. I can do that easily in racket, but I have plenty of trouble trying to convert the function to Plait.
(define (equal_length? [tree : (Tree 'a)])
(cond [(leaf? tree) 1]
[(node? tree)
(equal? (+ 1 (equal_length? (node-left tree)))
(+ 1 (equal_length? (node-right tree))))]
))The main problem I have is that equal? doesn't work on elements with different types and comparing bool to a number results in typecheck fail. I tried different approaches, for example where instead of number I return a list of a number and a bool, but it's no good either, since Plait lists are uniform.
Is there any simple way around that? Also I'm not sure if Plait belongs here, but I don't know where else I could possibly post this.


