Stream: ideas

Topic: Explicitly not importing types from the standard library


view this post on Zulip Ayaz Hafiz (Sep 21 2022 at 15:56):

Currently, you can't define types in a roc module that have the same name as a builtin type. For example, I can't have something like

interface F imports [] exposes []

Result o e : [Err e, Ok o]

because Result is already provided, by default, in every scope. Usually this is not a problem (why re-define Result?), but it can be a problem for more specialized types. For example, once we import Decode by default into every scope, this module will break. That is a more reasonable use case; rather than the generic Decoding interface, this module wants to expose a base64-specialized decoder

view this post on Zulip Ayaz Hafiz (Sep 21 2022 at 15:57):

The question is, would it make sense for Roc to support a way to explicitly opt-out of default import of standard library types?

view this post on Zulip Ayaz Hafiz (Sep 21 2022 at 15:58):

I am inclined to say "no", and that you should instead use names unique from the standard library (helps avoid ambiguity in the community, especially if we expect the standard library to be relatively small). In user space, name collisions will be resolved with package namespaces.

view this post on Zulip Richard Feldman (Sep 21 2022 at 16:01):

yeah agreed

view this post on Zulip Richard Feldman (Sep 21 2022 at 16:02):

The question is, would it make sense for Roc to support a way to explicitly opt-out of default import of standard library types?

implicit in the question is "would it make sense for Roc to support alternate stdlibs?" because they will definitely be created and advertised if it's possible to do this :big_smile:

view this post on Zulip Richard Feldman (Sep 21 2022 at 16:02):

I think for some languages, alternate stdlibs make a lot of sense, but I don't think Roc is one of those languages

view this post on Zulip Ayaz Hafiz (Sep 21 2022 at 16:03):

Good point

view this post on Zulip Martin Stewart (Sep 21 2022 at 16:30):

For Elm, I've found it annoying that it automatically imports certain modules and types. That said, for me it was because I wanted to make my own replacement for Cmd and Sub and ended up having to use different names. Roc doesn't have any effects in its standard library so this is not a problem.

view this post on Zulip Matthieu Pizenberg (Sep 22 2022 at 08:10):

Hi, not sure if this is exactly the question asked, but one big selling point of Rust is nostd. It's one of the very few languages able to challenge C on that front. Having a way of limiting Roc std could be nice too?

view this post on Zulip Arya Elfren (Sep 22 2022 at 10:13):

Well the benefits of nostd iirc is that std does allocations and other things that aren't universal (like in embedded). Languages like zig have an allocator interface that mean std is completely applicable and there is no need for nostd. I think roc is in a similar situation where any effect goes through the platform and so you can just use Std in any environment.

view this post on Zulip Brendan Hansknecht (Sep 22 2022 at 13:42):

Yeah, roc is pretty flexible in that sense. I have already run roc on a microcontroller where the platform was a nostd rust application. There are two main options for something like this:

  1. Panic/print a debug message when some code calls roc_alloc. You will lose access to lists and strings, but otherwise everything works fine. Static compile time known lists and strings should still be fine.
  2. Modifyroc_alloc to pull from a limited pool of bytes like a static array. Then if roc uses over that much memory, you can decide how to handle it.

I think roc could potentially handle this a bit more gracefully, but the general idea should work.

view this post on Zulip Richard Feldman (Sep 22 2022 at 14:02):

technically small strings work too, but you gotta be careful :sweat_smile:

view this post on Zulip Brendan Hansknecht (Sep 22 2022 at 14:10):

Oh, and roc only supports 32bit and 64bit platforms. So that limits microcontroller options.

view this post on Zulip Richard Feldman (Sep 22 2022 at 14:13):

true, although in theory others are possible

view this post on Zulip Brendan Hansknecht (Sep 22 2022 at 14:14):

For sure. Would be very interesting to see roc on an Arduino where the platform covers all of the core io and such.

view this post on Zulip Arya Elfren (Sep 23 2022 at 12:26):

Yea. Just plug in a zig buffer allocator and you're good to go.

view this post on Zulip Arya Elfren (Sep 23 2022 at 12:28):

Then you can apply what tigerbeetle does for their memory to roc. Allocate it all up front in zig and roc thinks it's requesting new memory when you already own it.

view this post on Zulip Brendan Hansknecht (Sep 23 2022 at 13:53):

Yep. Totally doable in roc. You are just more likely to run into issues because it is harder to tracker your allocations and their sizes. Just more likely you will use more than you expect or incur accidental copies than with zig alone.


Last updated: Jun 16 2026 at 16:19 UTC