News for hackers. Stuff that matters.
Re:Zig's Comptime Is Bonkers Good by James_K on Tuesday January 07, 2025 @01:24PM (#42625581)
Functions can crash anyway. I don't see how what you describe is different from a function on integers that errors on inputs that are too big. The programmer has to actively choose to make function break parametricity, and they can equally chose not to do that.
Re:Zig's Comptime Is Bonkers Good by josephg on Tuesday January 07, 2025 @04:42PM (#42627927)
In an ideal world, a function that only works for small integers would bake that into its type system. Ie, rather than accepting “any integer”, the function would accept a u8, or a value compile-time guaranteed in the range of 0..10 or something.

Your point still stands though. Modern programming languages don’t constrain you much at all with their type systems.

I spent a little time in Haskell a few years ago and it the kind of reasoning you can do about functions is wild. Eg, if a function has the type signature of A -> A, we know the function has to be the identity function because that’s the only function that matches the type signature. (Well that or the “bottom function”, which loops forever). Lots of functions are like that - where the type definitions alone are enough to reason about a lot of code.

Re:Zig's Comptime Is Bonkers Good by James_K on Tuesday January 07, 2025 @06:03PM (#42628775)
Haskell has quite a few partial functions in the standard library if I recall. Bog standard (!!), head, and tail for lists; fromJust to unwrap Maybes; and even some more interesting examples like "all" which mightn't work on infinite lists. Indeed any Turing-complete language includes partial functions of that final variety.
Re:Zig's Comptime Is Bonkers Good by _aavaa_ on Wednesday January 08, 2025 @09:50AM (#42634812)
> In an ideal world, a function that only works for small integers would bake that into its type system. Ie, rather than accepting “any integer”, the function would accept a u8, or a value compile-time guaranteed in the range of 0..10 or something.

Ada takes this approach.