I've been a huge fan of @Ian Mackenzie 's packages in Elm. I use a bunch of them for a space simulation thing I've been building and they've helped me to not mix numbers with different units (which there are lot of in space). Even more so with making sure things are scaled properly! So I started playing porting them to Roc. Not sure how far I'll get (there's a lot of work) but it's a fun way to learn Roc Screen-Shot-2022-09-16-at-2.56.56-PM.png
Currently taking the Breakout example app and wrapping values
I love that I can have Bounds
and Rect
implicitly convert from/to Rust f32 and a wrapped Roc Quantity F32 Pixels
. Makes it so the platform gives and takes pixels.
This is satisfying :)
Trying to migrate the existing Rect
to a shapes like those in elm-geometry
and struggling with getting a Point3d
to work. Some of it is definitely me trying to write Elm in Roc :sweat_smile:
Trying to figure out how to be able to set a Point3d a units coordinates := { x : a, y : a, z : a }
in my Model. Wondering if I need to be more constrained with my a
:thinking:
I mean. You might want Num a
, but that shouldn't be an error
What error are you getting with that struct?
I keep getting thread '<unnamed>' panicked at 'called
Result::unwrap() on an
Err value: Erroneous', crates/compiler/mono/src/ir.rs:3228:18
when I have
Model : {
ballPosition : Point3d Pixels ScreenSpace,
}
Model : {
ballPosition : Point3d Pixels ScreenSpace,
}
init ...
{ ballPosition: Point3d.pixels
(width |> Quantity.scaleBy 0.5 |> Pixels.inPixels)
(height |> Quantity.scaleBy 0.4 |> Pixels.inPixels)
(0),
}
width |> Quantity.scaleBy 0.5 |> Pixels.inPixels
and give an a
, which I think should be an F32
in this case
Same error with ballPosition: Point3d.pixels 5.0f32 10.0f32 0.0f32,
(trying to eliminate other causes)
Maybe I need to be defining Point3d
in the Rust part of the platform?
Shouldn't point3d take 3 values, not 2? At least based on the definition
Also, not sure it will give you a better error, but make sure to try roc check
if you hit compiler errors. It tends to give better errors and not crash.
Thanks @Brendan Hansknecht ! Running check
found the issue. I'd only written imports [ pf.Point3d ]
and not pf.Point3d.{Point3d}
:face_palm:
Ah
Cool
Glad to help
I've found it easier to catch these simple mistakes by using http://eradman.com/entrproject/, running it like find ./examples/roc-geometry/**/*.roc | entr -s 'cargo run check examples/roc-geometry/breakout-2.roc'
I don't know what I did, but my branch https://github.com/wolfadex/roc/tree/wolfadex/roc-geometry just hangs when running cargo run check examples/roc-geometry/breakout-2.roc
and cargo run run examples/roc-geometry/breakout-2.roc
. Even inserting a bad value like carl = 5 * "steve"
at the top doesn't get it to fail
I think it was a circular import. Vector3d
imported Direection3d
, which imported Vector3d
(bad copy paste)
Can you file an issue with a minimal repro. Would be good to print a proper error on something like this.
Already did, should have linked it here, https://github.com/roc-lang/roc/issues/4075
Last updated: Jul 06 2025 at 12:14 UTC