Skip to content

Add zipper exercise - #223

Merged
Anton-4 merged 6 commits into
exercism:mainfrom
ageron:add-zipper
Sep 21, 2026
Merged

Anton-4 merged 6 commits into
exercism:mainfrom
ageron:add-zipper

Conversation

@ageron

@ageron ageron commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Adds the Zipper exercise.

Note: The solution (.meta/Example.roc) contains a really ugly up function. I couldn't find a better way to implement it because it doesn't seem possible to easily add a default field to a record (see this Zulip discussion: #beginners > Cannot add fields to a record with default fields). That said, this is just an example solution, the stub (Tree.roc) remains reasonably elegant.

Note 2: I pondered whether I should provide the definition of the Zipper type. I chose to leave it out because thinking about how you might design a zipper is half the fun. My original solution was horrible, so I eventually cheated and asked an AI how zippers are typically implemented for trees. Coming up with something and then learning about something better was a much better learning experience than simply being handed the best design from the start. Once you know the design, implementing it isn't too difficult.

Note 3: in my solution, the Crumb type is currently:

	Crumb : [
		Left({ value : U64, right : Try(Tree, [MissingField]) }),
		Right({ value : U64, left : Try(Tree, [MissingField]) }),
	]

Once the discussion about adding default fields to records is resolved, it will probably be better to implement it as:

	Crumb : [
		Left({ value : U64, right ?: Tree }),
		Right({ value : U64, left ?: Tree }),
	]

@kotp

kotp commented Sep 16, 2026

Copy link
Copy Markdown
Member

I eventually cheated and asked

This is not cheating, since Exercism is not a testing platform. This is a learning platform, and asking for help is definitely not cheating.

@Anton-4

Anton-4 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Is this ready to merge @ageron? I am mainly wondering if it's feasible for exercism students to find the elegant solution or if it will mostly be frustrating :p

@ageron

ageron commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing, @anton. Yes, I believe it's ready to merge: it's difficult but doable, and we don't have that many difficult exercises, so I think it's ok.

@Anton-4 Anton-4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ageron!

@Anton-4
Anton-4 merged commit 368d2c5 into exercism:main Sep 21, 2026
2 checks passed
@ageron
ageron deleted the add-zipper branch September 22, 2026 04:23
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.

3 participants