Const effect? - Polysemy

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Sridhar Ratnakumar

Not sure what the right name for this notion is ... but I'm looking for:

constEffect :: Sem (eff ': r) -> Sem (eff ': nil ': r)

The idea is that if I have a 'eff' program, and I want to create another program that includes instructions from 'eff' and 'nil' effects, return me that program even though the actual program contains instructions only from 'eff'.

Sridhar Ratnakumar

(I do some funky merging of multiple effects, but some functions only give programs with individual effects.)

Sridhar Ratnakumar

The mtl analog would be lift, right?

TheMatten

There's internal raiseUnder (I don't think it's internal for any serious reason)

Sridhar Ratnakumar

Oh thanks! That actually compiled haha

TheMatten

I think lift corresponds to raise, which adds layer on top

TheMatten

Hmm, I wonder if there's anything inherently unsafe in Polysemy.Internal :thinking:

Sridhar Ratnakumar

Can raise (or raise . raise ....) be avoided in the case of a program that supports multiple effects?

someProg :: Sem '[A, B, C] -> (AVal, BVal, CVal)
someProg prog = runWithPlugins prog

someProg $ do
  commandFromA
  raise $ commandFromB
  raise $ raise $ commandFromC
Sridhar Ratnakumar

Think of A, B, C as "plugins" in my software. At the user level I want the plugins to provide the commands the user (me) is supposed to use to write their program in. Having to use 'raise' brings in the knowledge of plugin hierarchy, which is an abstraction leak.

TheMatten

Oh, you don't want to be concrete in rows of effectful computations - that's something for interpreters/combinators - instead write Members '[A, B, C] r => Sem r a

Sridhar Ratnakumar

But with Members you can't specify that A, B, C are the exclusive list of effects (i.e., there are no other effects), can you?

TheMatten

commandFrom{A,B,C} should be polymorphic - someProg is final, concrete interpreter

Sridhar Ratnakumar

Gotcha. I had several functions defined monomorphically using Sem '[...] a. That was the culprit.

Sridhar Ratnakumar

This now getting to be fun.

Love Waern (King of the Homeless)

raiseUnder ain't internal. Use it as muxh you want.