polysemy-1.9.0.0: Higher-order, low-boilerplate free monads.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Polysemy.Opaque

Description

The auxiliary effect Opaque used by interpreters of Scoped

Synopsis

Effect

newtype Opaque (e :: Effect) m a Source #

An effect newtype meant to be used to wrap polymorphic effect variables to prevent them from jamming up resolution of Member. For example, consider:

badPut :: Sem (e ': State () ': r) ()
badPut = put () -- error

This fails to compile. This is because e could be State ()' -- in which case the put should target it instead of the concretely provided State (); as the compiler can't know for sure which effect should be targeted, the program is rejected. There are various ways to resolve this, including using raise or subsumeUsing. Opaque provides another way:

okPut :: Sem (e ': State () ': r) ()
okPut = fromOpaque (put ()) -- OK

Opaque is most useful as a tool for library writers, in the case where some function of the library requires the user to work with an effect stack containing some polymorphic effect variables. By wrapping the polymorphic effect variables using Opaque, users of the function can use effects as normal, without having to use raise or subsumeUsing in order to have Member resolve. The various interpreters of Scoped are examples of such usage of Opaque.

Since: 1.9.0.0

Constructors

Opaque (e m a) 

Interpreters

toOpaque :: Sem (e ': r) a -> Sem (Opaque e ': r) a Source #

Wrap Opaque around the top effect of the effect stack

fromOpaque :: Sem (Opaque e ': r) a -> Sem (e ': r) a Source #

Unwrap Opaque around the top effect of the effect stack