Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ex. 09 - unclear solution #33

Open
jgierer12 opened this issue Jun 18, 2019 · 1 comment
Open

Ex. 09 - unclear solution #33

jgierer12 opened this issue Jun 18, 2019 · 1 comment

Comments

@jgierer12
Copy link

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.

@jasim
Copy link
Contributor

jasim commented Jun 29, 2019

@jgierer12 Apologies for the slow response. You're right. The infix notation example is confusing - we'll remove it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants