News for hackers. Stuff that matters.
Re:Algebraic Effects for the Rest of Us by mrkeen on Saturday May 30, 2026 @03:32AM (#48333643)
No, they are function colouring. That's the point.

Someone writes a post lamenting red and blue functions, and everyone eats it up.

Substitute colour for something meaningful and the idea becomes idiotic.

"Top level function declares that it is non-blocking, but when I try to call a small blocking function from it, I have to change the declaration to blocking???"

Yes, yes you do.

Total functions can't call non-total functions.

Deterministic functions can't call nondeterministic functions.

Non-IO functions can't call IO functions.

Re:Algebraic Effects for the Rest of Us by captaincrowbar on Saturday May 30, 2026 @05:21AM (#48334297)
‘Non-IO functions can't call IO functions.’

How do you handle logging then? If f() calls g(), how can I add logging to g() without having to change or recompile f() (and everything in the call stack above it)? ‘You can’t’ is not an acceptable answer.

Re:Algebraic Effects for the Rest of Us by tome on Saturday May 30, 2026 @06:25AM (#48334667)
Not sure why people are saying "you can't" when it seems to me the whole point of algebraic effects that you can. You can define g so that it has no ability to do "general IO", all it can do is yield log messages. Then f can call g in a way that turns the log messages into writes to stdout. For example, here's how you would do it in Bluefin:

    type Log = Yield String
    
    -- workWithLogging cannot do arbitrary IO!
    -- All it can do is yield log messages, which
    -- must be processed elsewhere.
    workWithLogging  ::
      (e1 :> es) =>
      Log e1 ->
      Int ->
      Int ->
      Eff es Int
    workWithLogging l x y = do
      yield l ("x was " <> show x)
      yield l ("y was " <> show y)
      let result = x + y
      yield l ("result was " <> show result)
      pure result
    
    -- ghci> example
    -- x was 5
    -- y was 7
    -- result was 12
    -- 12
    example :: IO Int
    example = runEff $ \io -> do
      -- forEach determines how each log message
      -- should be handled.
      forEach
        (\l-> workWithLogging l 5 7)
        (\logMsg -> effIO io (putStrLn logMsg))
Re:Algebraic Effects for the Rest of Us by mrkeen on Saturday May 30, 2026 @07:04AM (#48334929)
"You can't" is simpler, because the inevitable reply is "but how do I do actual logging inside g"
Re:Algebraic Effects for the Rest of Us by tome on Saturday May 30, 2026 @07:17AM (#48335018)
"Actual logging" as in direct access to IO?
Re:Algebraic Effects for the Rest of Us by mrkeen on Saturday May 30, 2026 @07:36AM (#48335115)
Yes
Re:Algebraic Effects for the Rest of Us by mrkeen on Saturday May 30, 2026 @05:51AM (#48334479)
Don't declare it as non-logging.
Re:Algebraic Effects for the Rest of Us by CuriousSkeptic on Saturday May 30, 2026 @06:04AM (#48334568)
You can’t is an acceptable answer. The entitle point of such a feature is to prevent people from doing that.
Re:Algebraic Effects for the Rest of Us by codebje on Sunday May 31, 2026 @10:26PM (#48352007)
If `left_pad()` calls `send_env_vars()`, how can you add exfiltration to `send_env_vars()` without having to change `left_pad()` to expose the use of the network?

"You can't" should be the ONLY acceptable answer.