Skip to content

Conversation

rlmark
Copy link
Contributor

@rlmark rlmark commented Aug 26, 2022

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.

Copy link
Member

@ErikSchierboom ErikSchierboom left a 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!
Copy link
Member

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:
Copy link
Member

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.

Comment on lines +14 to +17
go acc = cases
[] -> acc
h :+ t -> go (Nat.increment acc) t
go 0 list
Copy link
Member

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.

Copy link
Member

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.

Comment on lines +21 to +23
[] -> false
h +: t | h === input -> true
h +: t -> contains input t
Copy link
Member

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 No newline at end of file
Copy link
Member

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]
Copy link
Member

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.

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

Successfully merging this pull request may close these issues.

2 participants