News for hackers. Stuff that matters.
Re:Moving Beyond Type Systems by fwlr on Friday May 31, 2024 @10:39PM (#40542442)
Later on the author makes the point that everything changes some various register deep in the guts of the CPU so by definition everything is always effect-full, but since we invented programming languages to get away from writing assembly, we shouldn’t consider that an effect when we’re not writing assembly. We invented many programming languages to get away from writing allocations and pointers into buffers too.
Re:Moving Beyond Type Systems by chuckadams on Friday May 31, 2024 @11:40PM (#40542687)
It’s usually implied that “effect” pertains to observable effects. Anything that doesn’t affect referential transparency gets handwaved away. A memoized function might use a private stateful cache, but as long as it doesn’t affect determinism, you can keep its existence secret.
Re:Moving Beyond Type Systems by _nalply on Saturday June 01, 2024 @09:42AM (#40545668)
A thought stroke me. Security struggles with timing leaks.

That programming language would need something like a timing effect to control timing leaks.

In such a programming language a memoized function is effectful on time.

Re:Moving Beyond Type Systems by jahewson on Saturday June 01, 2024 @12:02AM (#40542772)
If you print to stdout but nobody is around to read it, does it count as an effect?
Re:Moving Beyond Type Systems by sparkie on Saturday June 01, 2024 @01:02AM (#40543025)
Perfectly reasonable question.

Basically, you can consider it a NOP if there's no observable side-effect.

Obviously, stdout has a particular purpose and you wouldn't just disable the side-effect for one use case, but you could imagine having some pseudo console for the purpose of emitting debug messages which is considered a non-effect in your language (provided you can't read from it and reify the text back into values).

In .NET for example, you can use `Debug.Write` and `Trace.Write` for emitting debug messages, and these lines are erased from the release version of the binary. You can mark any void-returning function with the `[Conditional("DEBUG")]` attribute and have calls to it erased because the DEBUG symbol is not defined in release versions.

IMO, this should be standard in all languages - in languages with effects even moreso because we don't want to pass around an effect if our only use for it is debug or trace messages.

Re:Moving Beyond Type Systems by shirogane86x on Saturday June 01, 2024 @11:04AM (#40546318)
Haskell also has something like this in Debug.Trace.trace: even though it's _technically_ impure (cause it outputs to stdout), it's typed as a pure function because it's just for debugging (I think internally it uses an escape hatch to just hide the IO)
Re:Moving Beyond Type Systems by empath75 on Friday May 31, 2024 @11:04PM (#40542549)
Yeah, but you're losing one of the things that you get from pure functional languages, which is determinism. The same function run multiple times may return different results.