Skip to content
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

Add robot-simulator exercise #114

Merged
merged 1 commit into from
Sep 23, 2024
Merged

Conversation

ageron
Copy link
Contributor

@ageron ageron commented Sep 23, 2024

This exercise might be a good candidate for another opaque type. The stub currently looks like this:

module [create, move]

Direction : [North, East, South, West]
Robot : { x : I64, y : I64, direction : Direction }

create : { x ? I64, y ? I64, direction ? Direction } -> Robot
create = \{ x ? 0, y ? 0, direction ? North } ->
    crash "Please implement the 'create' function"

move : Robot, Str -> Robot
move = \robot, instructions ->
    crash "Please implement the 'move' function"

We could instead replace it with this:

module [create, move]

Direction : [North, East, South, West]
Robot := { x : I64, y : I64, dx : I64, dy : I64 }

create : { x ? I64, y ? I64, direction ? Direction } -> Robot
create = \{ x ? 0, y ? 0, direction ? North } ->
    crash "Please implement the 'create' function"

toRecord : Robot -> { x : I64, y : I64, direction : Direction }
toRecord = \robot ->
    crash "Please implement the 'toRecord' function"

move : Robot, Str -> Robot
move = \robot, instructions ->
    crash "Please implement the 'move' function"

The tests would look like this:

expect
    robot = create { direction: West }
    result = robot |> move "R" |> toRecord
    result == { x: 0, y: 0, direction: North }

Actually I'm not really sure it's a good idea, because it's a fairly easy exercise, which will likely appeal to beginners, and they may get frustrated by opaque type syntax, and the different representations of the robot direction. Wdyt?

Copy link
Contributor

@isaacvando isaacvando left a comment

Choose a reason for hiding this comment

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

Looks good! I agree that this could be a good place to use opaque types, but I think it is a good idea to avoid them to keep things simple for beginners like you suggest 👍

@ageron
Copy link
Contributor Author

ageron commented Sep 23, 2024

Thanks Isaac 👍

@ageron ageron merged commit e1dd4b4 into exercism:main Sep 23, 2024
4 checks passed
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