-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Adds List concept #59
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely! I've added some comments, which mostly revolve around prerequisites.
@@ -0,0 +1,84 @@ | |||
# Instructions | |||
|
|||
In this exercise you need to implement some functions to manipulate a list of programming languages. Some of the functions you'll be asked to define may exist for `List`, which is good to know for future reference, but for this exercise try not to use them! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the bit of text starting with "Some of the functions", you could consider putting them in a special block: https://exercism.org/docs/building/markdown/markdown#h-special-blocks-sometimes-called-admonitions
listText = ["hello", "world"] | ||
``` | ||
|
||
Unison implements lists as a finger tree, allowing for fast access of the first and last element. You can read more about the underlying implementation in the [standard library List documentation][list-docs]. Appending single elements to either side of the list can be done with the `+:` and `:+` operators: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do students need to know about the underlying implementation? I guess they don't, in which case it might be best to remove it here and just have it in the about.md
document.
go acc = cases | ||
[] -> acc | ||
h :+ t -> go (Nat.increment acc) t | ||
go 0 list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This uses recursion, which makes a lot of sense. That said, recursion is likely a concept you'd want to have as a prerequisite for this exercise, so it should probably be added as such to the config.json
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the same vein, this example also uses pattern matching, which you also want as a prerequisite here. In F#, the way we solved this is by having one introductory pattern-matching
exercise: https://github.com/exercism/fsharp/tree/main/exercises/concept/guessing-game
This exercise introduces basic pattern matching, and then the lists exercise builds on that by showing how to do pattern matching with lists specifically.
[] -> false | ||
h +: t | h === input -> true | ||
h +: t -> contains input t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This uses a guard pattern, which is likely either a separate prerequisite or part of a pattern-matching
prerequisite.
h +: t -> contains input t | ||
|
||
languageList.reverse : [Text] -> [Text] | ||
languageList.reverse list = List.foldLeft (b a -> a List.+: b ) [] list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is using higher-order functions, which should be a prerequisite. Note that I really like that the student gets to use a function from the List
module, as we want them understanding how to do that and where to find these functions. Another option would be to allow them to just use List.reverse
(if there is such a function). It would then be more about finding the right function, that figuring out how to reverse lists.
@@ -0,0 +1,26 @@ | |||
languageList.new : [Text] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Text
is being used here, it should be a prerequisite of this exercise.
Adding a List concept exercise and docs. It is marked WIP for now so it won't show up just yet.
Lists could be introduced in a number of ways but this one focuses on pattern matching and constructing lists via cons operators and recursion. Perhaps a List concept part 2 would talk more about maps and folds and other higher order functions.