There are some problems with your code:
- Function name should start with small case letters. Hence the record data structure should be like this:
data MyRecord = MyRecord {a, b :: Int, c :: Double, d :: (Int,Double)}
- And your function name should be like this:
myTree2MyRecord :: MyTree -> MyRecord
Now going through your actual code, you seem to be in almost right path. But in order to find the solution, you have to answer some of these questions:
What exactly does the
Int
denote ind :: (Int, Double)
?When you are pattern matching for data constructors like
A
,B
etc., you seem to be assigning the values of theMyTree
ADT to the record. Think about the recursive case there. What output do you want for input like this:
myTree2MyRecord (B 1 (B 1 (A 1)))
Your current implementation just discards the value of MyTree
in it:
myTree2MyRecord(B b1 myTree) = emptyRecord {b = b1}
Instead of discarding think what should happen to myTree
in this case. This will lead to a recursive solution.
And finally, formulate what output do you want for the input which you have given for the question:
test = B 1 ( B 1( D 0.02(A 2)))
Once you answer these question, I think you will refactor the code and solve this problem yourself.