DEV Community

Discussion on: Why algebraic effects matter in F#

Collapse
 
jim108dev profile image
jim108dev • Edited

Thank you for submitting this article. I have the following questions/remarks:

  1. "A common approach in the imperative/OO world is to use dependency injection (or plain old interfaces) to separate the logging API from its implementation. However, the resulting code still causes side effects."
let hypotenuse (log:string -> unit) a b =
    log $"Side a: {a}"
    log $"Side b: {b}"
    let c = sqrt <| (a*a + b*b)
    log $"Side c: {c}"
    c

let dummy _ = ()
let r2 = hypotenuse dummy 5.0 0.0
Enter fullscreen mode Exit fullscreen mode

dummy does not cause a side effect, does it?
'2. If the function in your example causes an exception for some reason only the exception is shown but not the log statements up to this point.

Collapse
 
shimmer profile image
Brian Berns
  1. You're right that dummy doesn't cause a side-effect, because it throws away its input. We're more interested here in logging functions that actually produce a log in the end.

  2. Yes, it's probably not a good idea to mix plain .NET exceptions with the sort of pure functional effect handling described here. At some point in the future, exceptions will perhaps become just another kind of pure functional effect, but we're not there yet.