Stream: beginners

Topic: name overloading


view this post on Zulip Artur Swiderski (Jun 03 2023 at 19:21):

I can't define few functions with the same name ? It would be possible since typing is strong here. I have to constantly invent new names , is this by design ??

view this post on Zulip Artur Swiderski (Jun 03 2023 at 19:35):

in general names recycling is very poor in this language I don't know if this is good or bad, In c++ as you may know by chance I can use the same names over and over again. As I said it may be good but is this design decision? or some missing features?

view this post on Zulip Brendan Hansknecht (Jun 03 2023 at 19:38):

It is definitely a design decision, but there has also been discussion around changing it and shadowing rules. I think it is something that could change in the future, but I don't have a well written explanation around why exactly these choices were made.

view this post on Zulip Brendan Hansknecht (Jun 03 2023 at 19:39):

Hopefully another dev will have more insight.

view this post on Zulip Brendan Hansknecht (Jun 03 2023 at 19:39):

Also #ideas > Shadowing & Redeclaration is at least kinda related

view this post on Zulip Martin Stewart (Jun 03 2023 at 19:43):

If I understand correctly, @Artur Swiderski is asking why it's not possible to do this:

a : Float -> Float
a = #implementation 1

a : Int -> Int
a = #implementation 2

foo = a 5.4 # The compiler figures out that I'm providing a float so the first implementation gets used

where as the shadowing and redeclaration discussion is about allowing a function to overwrite another in scope?

view this post on Zulip Brendan Hansknecht (Jun 03 2023 at 19:47):

For sure, I just see them as related in a sense. So I think insights and decisions on one can often relate to the other.

view this post on Zulip Artur Swiderski (Jun 03 2023 at 19:48):

Martin Stewart said:

If I understand correctly, Artur Swiderski is asking why it's not possible to do this:

a : Float -> Float
a = #implementation 1

a : Int -> Int
a = #implementation 2

foo = a 5.4 # The compiler figures out that I'm providing a float so the first implementation gets used

where as the shadowing and redeclaration discussion is about allowing a function to overwrite another in scope?

exactly this

view this post on Zulip Brendan Hansknecht (Jun 03 2023 at 19:55):

Specifically if you look at something like:

doSomething = \x ->
     a : Float -> Float
     a = #implementation 1

     a : Int -> Int
     a = #implementation 2

This is really no different from:

doSomething = \x ->
     a : Float
     a = #value 1

     a : Int
     a = #value 2

You are defining the same variable twice and doing it with different types.

view this post on Zulip Brendan Hansknecht (Jun 03 2023 at 19:57):

This is at least from the current compilers perspective.

view this post on Zulip Brendan Hansknecht (Jun 03 2023 at 20:01):

One other more specific note, it may lead to complications in type decidability:

a : U16 -> U16
a = #implementation 1

a : U8 -> U8
a = #implementation 2

foo = a 5 #what type are foo and 5? 5 is both a valid U8 and U16.

view this post on Zulip Anton (Jun 05 2023 at 09:52):

I think allowing this has more drawbacks than benefits.


Last updated: Jul 06 2025 at 12:14 UTC