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.
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!
You're partially right for the first part -- F# didn't allow slices to go out of bounds safely until F# 5.0. F# 5.0 returns an empty collection, while prior versions threw a runtime exception. I ran into this same issue just now.
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.
If results from your outside environment do not match those of Codewars, question whether those tests are in fact truly set up in the exactly same way. If not, trust the expectations of this site over anything else. Check error messages and proceed from there. Hope that helps.
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