Ad
  • Custom User Avatar

    Thanks for clarifying, I didn't know that.
    I also didn't know that the upper value in a range is included when iterating it using a for loop.
    I really like F#, but I feel that the error messages a lot of the times aren't descriptive enough, and because of that they will often have you look for the problem in the wrong location.
    Anyways thanks again!

  • Custom User Avatar

    Thanks for your answer. I figured that much, but I still do not get why I am seeing the error. As the function should be returning an int (and it is) then it should not throw a type mismatch error..? Or am I wrong here? The test could obviously fail if my code would be incorrect, but certainly not a type mismatch error?

    Update:

    It seems that Codewars cannot handle array slicing.
    I am making sub arrays using:
    let left = items.[0..index-1]
    let right = items.[index+1..]

    When I remove these slices from the code I am no longer seeing the error..
    I figure however that this is correct F# code as it builds and runs in Visual studio without any problem.

    Strange problem

    Update 2:
    In the end it wasn't the slicing that was a problem.
    I was iterating using a for loop with a range from 1..items.Length
    causing an index out of bounds mistake. This was however not reflected in the error output.

    Thanks anyways for your help.

  • Custom User Avatar

    Not sure why, but when I run the test in Visual studio it works, yet here I am getting a type mismatch error:
    /home/codewarrior/program.fsx(18,17): error FS0001: Type mismatch. Expecting a
    'int * int []'
    but given a
    'int * int [] * 'a'
    The tuples have differing lengths of 2 and 3

    But I am not using any tuples and the function is just returning an integer for the index. (so function signature is: int array -> int

    I am getting same error if just return any random integer.

    Can anyone help