|
|
|
|
|
by reuben364
1314 days ago
|
|
For the StrategyWithSetup example, my FP oriented brain would create another function: withSetup :: IO c -> IO d -> (a -> IO b) -> a -> IO b
withSetup mc md f = \ a -> do
mc
b <- f a
md
return b
Which is pretty identical except with a closure over functions in place of a class of abstract methods. Classes with abstract methods are effectively higher order functions, except differences in boilerplate.Another thing worth mentioning are language features that can't be implemented unless you effectively implement a DSL like automatic differentiation, call-cc, algebraic effects. Hooks in React are sort of like a poor man's algebraic effects. It can't affect the control flow so it relies on immutability and hooks to unconditionally run to operate. EDIT: after a bit of thinking, I realize that the unconditional ordering of hooks is really a way to identify call sites at runtime, which I don't think is related to algebraic effects. |
|