Stream: beginners

Topic: `empty` or `empty()`?


view this post on Zulip Aurélien Geron (Sep 29 2026 at 21:03):

I see that the standard library uses empty : () -> Foo rather than empty : Foo.

Is there a rationale for that? I tend to use plain constants rather than functions with no args whenever possible, so I'm curious to know why using a function is preferred?

view this post on Zulip Richard Feldman (Sep 29 2026 at 21:06):

it's because constants can't be polymorphic

view this post on Zulip Richard Feldman (Sep 29 2026 at 21:07):

like you can't do x : List(_a)

view this post on Zulip Richard Feldman (Sep 29 2026 at 21:07):

it's a weird edge case we talked about a long time ago :sweat_smile:

view this post on Zulip Aurélien Geron (Sep 29 2026 at 21:08):

view this post on Zulip Aurélien Geron (Sep 29 2026 at 21:17):

Thanks @Richard Feldman .
If the function is defined at the top-level and can be evaluated at compile time, then I suppose it will produce the same binary as if I had used a constant instead (of the correct concrete type), right?

view this post on Zulip Richard Feldman (Sep 29 2026 at 21:25):

yep!


Last updated: Oct 15 2026 at 17:56 UTC