Merged
Conversation
tbagrel1
commented
Feb 15, 2022
aspiwack
reviewed
Feb 22, 2022
| import qualified Control.Monad.Trans.Reader as NonLinear | ||
| import Data.Functor.Compose | ||
| import Data.Functor.Const | ||
| import Data.Functor.Const (Const (..)) |
Member
There was a problem hiding this comment.
When there is a conflict, I'd rather us use hiding (conflicting thing). It's more robust.
Member
Author
There was a problem hiding this comment.
There seems to be no conflict after all
Member
Author
aspiwack
approved these changes
Feb 23, 2022
Comment on lines
+132
to
+140
| -- 'transfer' was | ||
| -- > transfer (Pull.Array f n) = | ||
| -- > Push.Array (\k -> NonLinear.foldMap' (\x -> k (f x)) [0 .. (n - 1)]) | ||
| -- but 'Linear.Monoid' no longer implies 'NonLinear.Monoid'. So we can have | ||
| -- @mempty :: a@ and @(<>) :: a -> a -> a@ (by degrading 'Linear.<>'), but we | ||
| -- no longer have the 'NonLinear.Monoid' instance required to use | ||
| -- 'NonLinear.foldMap\''. As a result, we just expand 'foldMap\'' to its | ||
| -- definition in terms of 'foldl\'', which doesn't require 'NonLinear.Monoid': | ||
| -- > foldMap' f' = foldl' (\acc a -> acc <> f' a) mempty |
Member
There was a problem hiding this comment.
As a side note we still have that linear monoids have a corresponding classical monoid.
So we could have
newtype Linear a = Linear a
instance Semigroup a => Linear.Semigroup (Linear a) where
x <> y = x <> y
instance Monoid a => Linear.Monoid (Linear a) where
mempty = memptyThen you could in principle do
case NonLinear.Foldmap' (\x -> Linear (k (f x)) [0 .. (n - 1)] of
Linear r -> rIt's not better than a simple foldl', but it's worth being aware of the possibility (in an ideal world you would be able to use coerce, but coerce isn't linear).
There is also the option of using a linear foldMap', but we don't have it available until we solve the Foldable issue (e.g. #190 ).
67033b9 to
925d96f
Compare
+ Break relationship between `Data.Monoid.Linear.{Semigroup,Monoid} and their
non-linear counterparts (see #379)
+ Add as many instances as possible for these classes (to replicate what is done
in `base`
925d96f to
d131277
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Data.Monoid.Linear.{Semigroup,Monoid}and theirnon-linear counterparts (see Dependency between some linear classes and their non-linear counterpart (e.g.
Semigroup) #379)in
baseCloses #379. Closes #372.