Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9b4b5df

Browse files
author
Manuel Bärenz
committedMay 4, 2024
ReaderT instances for Semialign and Align
1 parent 5ba75bf commit 9b4b5df

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed
 

‎semialign/src/Data/Semialign/Internal.hs

+7
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import Data.Semigroup (Option (..))
8080

8181
import Data.These
8282
import Data.These.Combinators
83+
import Control.Monad.Trans.Reader (ReaderT (..))
8384

8485
oops :: String -> a
8586
oops = error . ("Data.Align: internal error: " ++)
@@ -454,6 +455,12 @@ instance SemialignWithIndex Int ZipList
454455
instance ZipWithIndex Int ZipList
455456
instance RepeatWithIndex Int ZipList
456457

458+
instance Semialign m => Semialign (ReaderT r m) where
459+
align ma mb = ReaderT $ getCompose $ align (Compose (runReaderT ma)) (Compose (runReaderT mb))
460+
461+
instance Align m => Align (ReaderT r m) where
462+
nil = ReaderT $ Prelude.const nil
463+
457464
-------------------------------------------------------------------------------
458465
-- semigroups
459466
-------------------------------------------------------------------------------

‎these-tests/test/Tests/Semialign.hs

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ alignProps = testGroup "Align"
9191
#ifdef MIN_VERSION_lattice
9292
-- note: with e.g. N5 (which isn't distributive lattice) distributivity laws fail!
9393
, semialignLaws (CZip :: CSemialign (Const M2))
94+
, semialignLaws (CAlign :: CSemialign (ReaderT Int []))
9495
#endif
9596
]
9697

0 commit comments

Comments
 (0)
Please sign in to comment.