Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
You get the
Number
type, but not the constructor ( note that you do get the deconstructor ).No, you are not supposed to use the constructor. Not a kata issue.
You are right on the necessary of keeping both parensToTree and treeToParens test. Then my only problem would be droping "" test in the parensToTree part. This will make two test parts totally sysmetry (3 lines t0 3 lines).
Thank you for this nice kata, anyway.
"you still have to deal with all strings"--> We are asked to encode "balanced parentheses", not random string input right? The description claims: "Binary trees can be encoded as strings of balanced parentheses". So, we expect the input should be balanced parentheses. Empty string "" is arguable to be balanced parentheses. Of course, "" could be included as valid input. My point is whether to encode "" to trees should be left optional to people.
I'm not sure I understand the issue here.
Mapping
"()"
to a leaf, and"(()())"
toLeaf :*: Leaf
can work, but you still have to deal with all strings, including""
. That's the puzzle: you need to figure out a representation that handles every possible string.If we only kept the
parensToTree (treeToParens Tree)
test case that would only show that treeToParens is a surjection, not a bijection. You need the other test to show it's a bijection.The empty string "" test case should be drop. Enforce this edge case implies solution had to map "" to Leaf.
As a counter example, I find maping () to a leaf, and (()()) to leaf :*: leaf is quit reasonable and should be a valid solution.
How about keeping only the ---parensToTree (treeToParens Tree)--- test cases. This will be enough to cover all possible string presentation.
I tried using the constructor and ran into this, too.
You don't need the constructor, though.
The kata is solvable with just the provided imports, so I don't think this is an issue.
Haskell version raised error:
"Data constructor not in scope: Number :: (p0 -> p1 -> p1) -> Number"
So, am I not supposed use Number constructor in the code?