Ad
  • Custom User Avatar

    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.

  • Default User Avatar

    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.

  • Default User Avatar

    "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.

  • Custom User Avatar

    I'm not sure I understand the issue here.

    Mapping "()" to a leaf, and "(()())" to Leaf :*: 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.

  • Default User Avatar

    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.

  • Custom User Avatar

    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.

  • Default User Avatar

    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?