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 ??
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?
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.
Hopefully another dev will have more insight.
Also #ideas > Shadowing & Redeclaration is at least kinda related
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?
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.
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
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.
This is at least from the current compilers perspective.
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.
I think allowing this has more drawbacks than benefits.
Last updated: Jul 06 2025 at 12:14 UTC