Skip to content

Commit

Permalink
Add NoThunks instances for WithEarlyExit
Browse files Browse the repository at this point in the history
  • Loading branch information
jasagredo committed Apr 16, 2024
1 parent 993baf5 commit e0a4062
Showing 1 changed file with 14 additions and 1 deletion.
@@ -1,4 +1,5 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE QuantifiedConstraints #-}
Expand Down Expand Up @@ -38,7 +39,7 @@ import Data.Proxy
import NoThunks.Class (NoThunks (..))
import Ouroboros.Consensus.Util ((.:))
import Ouroboros.Consensus.Util.IOLike (IOLike (..), PrimMonad (..),
StrictSVar, StrictTVar)
StrictSVar, StrictTVar, castStrictSVar, castStrictTVar)
import Ouroboros.Consensus.Util.NormalForm.StrictMVar (StrictMVar)

{-------------------------------------------------------------------------------
Expand All @@ -56,6 +57,18 @@ newtype WithEarlyExit m a = WithEarlyExit {
, MonadPlus
)

instance NoThunks (StrictTVar m a)
=> NoThunks (StrictTVar (WithEarlyExit m) a) where
showTypeOf _ = "StrictTVar (WithEarlyExit m)"
wNoThunks ctxt tv = do
wNoThunks ctxt (castStrictTVar tv :: StrictTVar m a)

instance NoThunks (StrictSVar m a)
=> NoThunks (StrictSVar (WithEarlyExit m) a) where
showTypeOf _ = "StrictSVar (WithEarlyExit m)"
wNoThunks ctxt tv = do
wNoThunks ctxt (castStrictSVar tv :: StrictSVar m a)

-- | Internal only
earlyExit :: m (Maybe a) -> WithEarlyExit m a
earlyExit = WithEarlyExit . MaybeT
Expand Down

0 comments on commit e0a4062

Please sign in to comment.