Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReaderT instances for Semialign and Align #196

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions semialign/src/Data/Semialign/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import Data.Semigroup (Option (..))

import Data.These
import Data.These.Combinators
import Control.Monad.Trans.Reader (ReaderT (..))

oops :: String -> a
oops = error . ("Data.Align: internal error: " ++)
Expand Down Expand Up @@ -454,6 +455,12 @@ instance SemialignWithIndex Int ZipList
instance ZipWithIndex Int ZipList
instance RepeatWithIndex Int ZipList

instance Semialign m => Semialign (ReaderT r m) where
align ma mb = ReaderT $ getCompose $ align (Compose (runReaderT ma)) (Compose (runReaderT mb))

instance Align m => Align (ReaderT r m) where
nil = ReaderT $ Prelude.const nil

-------------------------------------------------------------------------------
-- semigroups
-------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions these-tests/test/Tests/Semialign.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ alignProps = testGroup "Align"
#ifdef MIN_VERSION_lattice
-- note: with e.g. N5 (which isn't distributive lattice) distributivity laws fail!
, semialignLaws (CZip :: CSemialign (Const M2))
, semialignLaws (CAlign :: CSemialign (ReaderT Int []))
#endif
]

Expand Down