zesterer / tao

A statically-typed functional language with generics, typeclasses, sum types, pattern-matching, first-class functions, currying, algebraic effects, associated types, good diagnostics, etc.
https://tao.jsbarretto.com/
Mozilla Public License 2.0
1.09k stars 23 forks source link

How are you going to make division total? #28

Closed pkoch closed 2 years ago

pkoch commented 2 years ago

Everyone cheats on that one.

zesterer commented 2 years ago

For reals, division is already total. For integers, there are two options:

I think I'd tend towards the former as the more natural option, with the latter as an independent function.

Obviously, this doesn't account for division by zero though: it might be necessary to have some way to express that a value is non-zero in the type system, such as through dependent types.

Ideas are welcome!

pkoch commented 2 years ago

Obviously, this doesn't account for division by zero though: it might be necessary to have some way to express that a value is non-zero in the type system, such as through dependent types.

Yeah, this was more my point. I see you've resisted the common cheat of making Zero - Succ(Zero) == Zero, I was wondering what you have in mind to prevent zero divisions. They do feel like something a dependent type system can tackle. However, I've never seen in implemented, hence the question.

Cheers, and great work! 👏