Skip to content

Commit

Permalink
NFData for CoRec Identity
Browse files Browse the repository at this point in the history
  • Loading branch information
dfithian committed Dec 15, 2023
1 parent 63a8025 commit e9ab7e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/Composite/CoRecord.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Composite.CoRecord where

import Prelude
import Composite.Record (AllHave, HasInstances, (:->)(getVal, Val), reifyDicts, reifyVal, val, zipRecsWith)
import Control.DeepSeq (NFData, rnf)
import Control.Lens (Prism', Wrapped, Unwrapped, prism', review, view, _Wrapped')
import Control.Monad.Except (ExceptT, throwError, withExceptT)
import Data.Functor.Contravariant (Contravariant(contramap))
Expand Down Expand Up @@ -41,6 +42,13 @@ instance forall rs. (RMap rs, RecAll Maybe rs Eq, RecApplicative rs, RecordToLis
f (Compose (Dict a)) b = Const $ a == b
toRec = reifyConstraint . fieldToRec

instance forall rs. (AllHave '[NFData] rs, RecApplicative rs) => NFData (CoRec Identity rs) where
rnf (CoVal (Identity x)) = rnf' x
where
rnfer :: Rec (Op ()) rs
rnfer = reifyDicts (Proxy @'[NFData]) (\ _ -> Op rnf)
rnf' = runOp (rget rnfer)

-- |The common case of a 'CoRec' with @f ~ 'Identity'@, i.e. a regular value.
type Field = CoRec Identity

Expand Down
6 changes: 0 additions & 6 deletions src/Composite/Record.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ instance Monad ((:->) s) where
instance NFData a => NFData (s :-> a) where
rnf (Val x) = rnf x

-- instance NFData (Record '[]) where
-- rnf RNil = ()

-- instance (NFData x, NFData (Record xs)) => NFData (Record (x : xs)) where
-- rnf (x :& xs) = rnf x `seq` rnf xs

instance forall (s :: Symbol) a. (KnownSymbol s, Show a) => Show (s :-> a) where
showsPrec p (Val a) = ((symbolVal (Proxy :: Proxy s) ++ " :-> ") ++) . showsPrec p a

Expand Down

0 comments on commit e9ab7e2

Please sign in to comment.