I am trying to create a singular function in class Traceable that lets me take both binary and variable trees and output a list of lists of all possible paths to leaves. I can't seem to compile and have been racking my brain trying to figure it out for hours. If someone could give me a hand that would be amazing.
This is my code
data Tree a = Null | Node a [Tree a] deriving Show
data BinTree a = Nil | Vertex a (BinTree a) (BinTree a) deriving Show
class Traceable a where
trace :: (BinTree a, Tree z) => z a -> [a]
instance Traceable (BinTree a) where{
trace Nil = []
trace (Vertex x l r) = trace l ++ [x] ++ trace
instance Traceable (Tree a) where{
trace Null = []
trace (Node a x) = [a] ++ (trace (head x))}
I am getting this error
* Expected a constraint, but `BinTree a' has kind `*'
* In the type signature:
trace :: (BinTree a, Tree z) => z a -> [a]
In the class declaration for `Traceable'
* Expected a constraint, but `Tree z' has kind `*'
* In the type signature:
trace :: (BinTree a, Tree z) => z a -> [a]
In the class declaration for `Traceable'
* Expecting one fewer argument to `z'
Expected kind `* -> *', but `z' has kind `*'
* In the type signature:
trace :: (BinTree a, Tree z) => z a -> [a]
In the class declaration for `Traceable'
Edit: This is a school project for me and I can't use any Haskell extensions
Doing what you suggested it got a ton further but I still have a couple of errors.
* Expecting one fewer argument to `BinTree a'
Expected kind `* -> *', but `BinTree a' has kind `*'
* In the first argument of `Traceable', namely `BinTree a'
In the instance declaration for `Traceable (BinTree a)'
* Expecting one fewer argument to `Tree a'
Expected kind `* -> *', but `Tree a' has kind `*'
* In the first argument of `Traceable', namely `Tree a'
In the instance declaration for `Traceable (Tree a)'
Edit #2 Thanks for your help, taking out the a from BinTree instantiation seems to have created another problem
* Couldn't match expected type `[a]'
with actual type `t0 a0 -> [a0]'
* In the second argument of `(++)', namely `trace'
In the second argument of `(++)', namely `[x] ++ trace'
In the expression: trace l ++ [x] ++ trace
* Relevant bindings include
r :: BinTree a (bound at tree.hs:11:20)
l :: BinTree a (bound at tree.hs:11:18)
x :: a (bound at tree.hs:11:16)
trace :: BinTree a -> [a] (bound at tree.hs:10:2)