You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm a bit confused about the intended solution for exercise 09:
/* Write a function to construct a list of all integers in the range [from,to_] in increasing order. let range: (int, int) => list(int)*/
let range = (from, to_) => failwith("For you to implement");
Since this lesson is about the infix append operator @, I would think that it's supposed to be used here. Also, the function isn't declared as rec in the template, which makes me believe that we are expected to solve it with a non-recursive function.
However, with my current knowledge of reason I don't know how to do this without recursion. (I'm sure it is possible somehow, I just don't think that the skillset of ex. 1-9 allows it). And I can't think of a solution where @ would be better than the rest operator. The only solution I can come up with is this or its variations:
let rec range = (from, to_) => if(from < to_) {
[from, ...range(from + 1, to_)]
else {
[]
};
However that solution doesn't fit into the learning flow at all IMO since it doesn't use anything new, especially not the new @ operator that this exercise is supposed to be about (yes you could [from] @ range(...) but that's not a proper use of append IMO). Also it is recursive without being declared as such in the template, which doesn't match with any previous or upcoming exercises where a function is always declared as recursive if expected to be solved that way.
Could you clarify whether my solution is the intended one? If so I would suggest adding the rec declaration to the template, in order to make it a bit more apparent that it is supposed to be solved with recursion too.
The text was updated successfully, but these errors were encountered:
I'm a bit confused about the intended solution for exercise 09:
Since this lesson is about the infix append operator
@
, I would think that it's supposed to be used here. Also, the function isn't declared asrec
in the template, which makes me believe that we are expected to solve it with a non-recursive function.However, with my current knowledge of reason I don't know how to do this without recursion. (I'm sure it is possible somehow, I just don't think that the skillset of ex. 1-9 allows it). And I can't think of a solution where
@
would be better than the rest operator. The only solution I can come up with is this or its variations:However that solution doesn't fit into the learning flow at all IMO since it doesn't use anything new, especially not the new
@
operator that this exercise is supposed to be about (yes you could[from] @ range(...)
but that's not a proper use of append IMO). Also it is recursive without being declared as such in the template, which doesn't match with any previous or upcoming exercises where a function is always declared as recursive if expected to be solved that way.Could you clarify whether my solution is the intended one? If so I would suggest adding the
rec
declaration to the template, in order to make it a bit more apparent that it is supposed to be solved with recursion too.The text was updated successfully, but these errors were encountered: