Skip to content

Migrate to new roc#198

Draft
ageron wants to merge 165 commits into
mainfrom
migrate-to-new-roc
Draft

Migrate to new roc#198
ageron wants to merge 165 commits into
mainfrom
migrate-to-new-roc

Conversation

@ageron

@ageron ageron commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

This PR migrates the Roc track to the new zig-based Roc compiler and its new syntax.

At the time of writing:

  • 92 exercises have been migrated and all their tests pass.
  • 4 exercises have been migrated but compilation fails: alphametics, complex-numbers, protein-translation and strain.
  • 14 exercises are partially migrated (i.e., only the tests):
    • 7 exercises shouldn't be too hard to finish migrating: forth, go-counting, grep, poker, rational-numbers, tournament, and zebra-puzzle.
    • 7 exercises depend on external libraries, so they will be impossible to migrate until these libraries are migrated. This includes anagram (unicode), gigasecond (isodate), meetup (isodate), micro-blog (unicode), rest-api (json), reverse-string (unicode) and sgf-parsing (roc-parser)

ageron added 30 commits June 9, 2026 16:55
Comment thread exercises/practice/error-handling/.docs/instructions.append.md Outdated
Comment thread exercises/practice/error-handling/.docs/instructions.append.md Outdated
Comment thread exercises/practice/complex-numbers/ComplexNumbers.roc Outdated
Comment thread exercises/practice/complex-numbers/ComplexNumbers.roc Outdated
Comment thread exercises/practice/rational-numbers/.meta/Example.roc Outdated
Comment thread exercises/practice/list-ops/.docs/instructions.append.md
Comment on lines +2 to +5
new : { real : F64, imag : F64 } -> Complex
new = |{ real, imag }| {
crash "Please implement the 'new' function"
}

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.

Constructors are redundant in Roc, is there a special reason why it was introduced here?

@ageron ageron Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh? But a {real, image} is not a Complex unless Roc can tell that it's the type we expect, right? For example, the following code causes an error because the conjugate method actually returns a {real, image}, not a Complex.

Complex := { real : F64, imag : F64 }.{
	conjugate = |z| { real: z.real, imag: -z.imag }  # Error
}

So I need to add a type annotation to get what I want:

Complex := { real : F64, imag : F64 }.{
	conjugate : Complex -> Complex
	conjugate = |z| { real: z.real, imag: -z.imag }  # Now OK
}

Such type annotations are not always very ergonomic, for example:

main! = |_| {
	z1 : Complex
	z1 = { real: 1.23, imag: 4.56 }
	z2 : Complex
	z2 = { real: 7.89, imag: 1.23 }
	z3 = z1 + z2
	dbg z3
	Ok({})
}

versus:

main! = |_| {
	z1 = Complex.new({ real: 1.23, imag: 4.56 })
	z2 = Complex.new({ real: 7.89, imag: 1.23 })
	z3 = z1 + z2
	dbg z3
	Ok({})
}

I believe Jared has been working on a nicer syntax like Complex({real: 123, imag: 4.56}): it would definitely remove the need for contructors. I propose to remove new once this syntax is available.

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