Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    You can encode maybe as well

  • Default User Avatar
  • Default User Avatar

    It's fixed now. Please confirm.

  • Default User Avatar

    Let me check

  • Custom User Avatar

    (I see that you have done it in the original church and his student way, but I think it is somewhat inelegant to use a pair)

  • Custom User Avatar

    You are right. I will fix this soon (currently writing paper, sorry)

  • Default User Avatar

    Hi,

    Thanks for the comment. The reason, I used Maybe [Int] -> Int is that I followed the original kata (in C#) which distinguishes between null and empty list. The F# translation created by the author of the Kata uses Option type i. e. F#'s equivalent of Maybe.

    The [Int] -> Maybe Int wouldn't correspond with the description:

    If array is empty, null or None, or if only 1 Element exists, return 0.

    Regards,

    suic

  • Custom User Avatar

    It really doesn't have to be that bad, a slightly more reasonable point-free solution would be:

    replaceAll = flip (flip . (map .) . flip (ap . flip flip (listToMaybe . join replicate . fromEnum) . ((.) .) . flip maybe . const) . (==))
    

    Edit:
    And with the bool function found in more recent versions of GHC, you don't even need the Bool -> Int -> [Int] -> Maybe Int hack:

    replaceAll = flip (flip . (map .) . flip (ap . bool) . (/=))
    
  • Custom User Avatar

    actually it's machine-generated code from a stack based idea

  • Custom User Avatar

    I didn't intend to have exta whitespaces, it is a "surprise" of Quickcheck random test cases... To have all things equal through all the languages of this kata I filter them now. Please could you try again and tell me if everything is correct?

  • Custom User Avatar

    I will try to look at that:-( Please could you tell me what is your: ["opu","","","vgsyk","b"] input string splitted on whitespaces? For now I changed test2 so that the input string be printed, maybe it will permit to see where the mistake is... It comes certainly from extra whitespaces in the input string.

    Edit: I think that the expected is the good one because of the whitespaces: ".OPU..VGSYK.b" but I have a doubt about the spaces between OPU and VGSYK in the expected you gave. Must be there 2 spaces but in your post it seems that there is only one. Here I have put dots instead of spaces.

  • Custom User Avatar

    I have been thinking about this. Even I think that type ErrorString = String Either ErrorString String is more idiomatic.

    But on other hand kata description says that function must be called get_reversed_color and exception should be raised.

    Do you suggest to not take a look at this? or change kata description?

  • Custom User Avatar

    Thanks, I think I've applied all those changes, can you check and see if it's ok now?

  • Custom User Avatar

    It is normal. Didn't you see in "Your test cases" or in "Test Cases" that the tests have the following form:

    "abs(actual - expected) must be <= 1 but was "

    It is a kind of fuzzy test to avoid truncating or rounding problems that happen frequently and cause so much arguing. I didn't put it in the description because I thought it would be obvious for someone seeing the tests but I will write it in the description to please you:-)
    Thanks for the feedback.

  • Loading more items...