I'm working through Advent and I made a type alias called MoveCommand that consists of a Direction tag union and a Nat for the distance. Here are the definitions:
MoveCommand : Direction Nat
Direction : [Up, Down, Forward]
But it seems that Nat in this case is being interpreted as a type argument to Direction in this case and I get this error:
── TOO MANY TYPE ARGUMENTS ───────────────────────────────────────── day02.roc ─
The Direction alias expects 0 type arguments, but it got 1 instead:
29│ MoveCommand : Direction Nat
^^^^^^^^^^^
Are there missing parentheses?
────────────────────────────────────────────────────────────────────────────────
Is there a way for me to create a MoveCommand type that can only consist of a Direction and a Nat without using a type argument, so that Nat is the only option?
You could something like
Direction : [Up Nat, Down Nat, Forward Nat]
up : Nat -> Direction
up = \distance -> Up distance
expect
whichDirection = up 50
expectedResult = Up 50
whichDirection == expectedResult
I used List [Fd U64, Up U64, Dn U64] but didn't alias it as its own type at the time as I hadn't figured out how to do that.
I find roc repl to be really helpful when trying new type definitions like this.
Screen-Shot-2022-10-19-at-08.30.44.png
I made a type alias called
MoveCommandthat consists of aDirectiontag union and aNatfor the distance
so the way this is written, it's actually specifying something else:
MoveCommand : Direction Nat
this is syntactically equivalent to MoveCommand : List Nat - it's basically saying "MoveCommand is a type alias for a Direction of Nats, because Direction is a type that has a type parameter (just like List does), and I'm specifying Nat for that type parameter here"
so if you want it to store both, you could make it a record, e.g.
MoveCommand : {
direction : Direction,
distance : Nat
}
Gotcha that makes sense, thanks to you both :+1:
Austin Clements has marked this topic as resolved.
Last updated: Nov 09 2025 at 12:14 UTC