anachronauts / jeff65

a compiler targeting the Commodore 64 with gold-syntax
GNU General Public License v3.0
6 stars 0 forks source link

Type inference #18

Open jdpage opened 6 years ago

jdpage commented 6 years ago

I think it could be helpful to provide simple type inference for let and for statements, to make the language a little cleaner. So the following would be allowed:

let x: u8 = 7
let y = x  --[[ y is u8 ]]

let z: [u16; 4] = [1, 2, 3, 4]
for w in z do
    --[[ w is u16 ]]
end

Since the type-checker has to derive what y and w should be anyway, it should be simple to allow it to just assume the type. (One might want y or w to be a longer type, but we'd still have to derive u8 and u16 respectively to determine which types are longer.)

woodrowbarlow commented 6 years ago

i am okay with this.

i only hesitate because i think explicit types always make code easier to read, but type inference does make refactors cleaner. so i'm on board.

jdpage commented 6 years ago

I definitely think that we should have explicit types in the function signatures, for what it's worth. I don't really see us having more complicated type inference than what I'm suggesting above.