module Control.Effect.Fix
  ( -- * Effects
    Fix(..)
  , module Control.Monad.Fix

    -- * Interpretations
  , fixToFinal

    -- * Threading utilities
  , threadFixViaClass

    -- * Carriers
  , FixToFinalC
  ) where

import Control.Monad.Fix

import Control.Effect
import Control.Effect.Primitive
import Control.Effect.Type.Fix

data FixToFinalH

instance (Carrier m, MonadFix m)
      => PrimHandler FixToFinalH Fix m where
  effPrimHandler :: Fix m x -> m x
effPrimHandler (Fix x -> m x
f) = (x -> m x) -> m x
forall (m :: * -> *) a. MonadFix m => (a -> m a) -> m a
mfix x -> m x
f
  {-# INLINEABLE effPrimHandler #-}

type FixToFinalC = InterpretPrimC FixToFinalH Fix

-- | Run a 'Fix' effect if the final monad and
-- all carriers transforming it are 'MonadFix'.
--
-- @'Derivs' ('FixToFinalC' m) = 'Fix' ': 'Derivs' m@
--
-- @'Prims'  ('FixToFinalC' m) = 'Fix' ': 'Prims' m@
fixToFinal :: ( Carrier m
              , MonadFix m
              )
           => FixToFinalC m a
           -> m a
fixToFinal :: FixToFinalC m a -> m a
fixToFinal = FixToFinalC m a -> m a
forall h (e :: Effect) (m :: * -> *) a.
PrimHandler h e m =>
InterpretPrimC h e m a -> m a
interpretPrimViaHandler
{-# INLINEABLE fixToFinal #-}