Skip to content

Commit

Permalink
Merge branch 'develop' into unconditional-th
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfmpe authored Nov 1, 2024
2 parents ca8fae0 + 5d2442f commit 7efee20
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 53 deletions.
2 changes: 0 additions & 2 deletions src/Control/Monad/ReaderIO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ instance Applicative (ReaderIO e) where
liftA2 = liftM2
{-# INLINE liftA2 #-}
#endif
(*>) = (>>)
{-# INLINE (*>) #-}

instance Monad (ReaderIO e) where
ReaderIO q >>= f = ReaderIO $ \e -> q e >>= \a -> runReaderIO (f a) e
Expand Down
4 changes: 3 additions & 1 deletion src/Data/AppendMap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ import qualified Data.Map.Internal.Debug as Map (showTree, showTreeWith)
#else
import qualified Data.Map as Map (showTree, showTreeWith)
#endif
#if !MIN_VERSION_witherable(0,3,2)
import qualified Data.Witherable as W
import Data.Map.Monoidal
import qualified Data.Map.Monoidal as MonoidalMap
#endif
import Data.Map.Monoidal


{-# DEPRECATED AppendMap "Use 'MonoidalMap' instead" #-}
Expand Down
19 changes: 10 additions & 9 deletions src/Reflex/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ import qualified Data.Dependent.Map as DMap
import Data.Functor.Compose
import Data.Functor.Product
import Data.GADT.Compare (GEq (..), GCompare (..))
import Data.FastMutableIntMap (PatchIntMap)
import Data.Foldable
import Data.Functor.Bind
import Data.Functor.Misc
Expand All @@ -220,8 +219,13 @@ import Data.String
import Data.These
import Data.Type.Coercion
import Data.Type.Equality ((:~:) (..))
#if MIN_VERSION_witherable(0,4,0)
import Witherable (Filterable(..))
import qualified Witherable as W
#else
import Data.Witherable (Filterable(..))
import qualified Data.Witherable as W
#endif
import Reflex.FunctorMaybe (FunctorMaybe)
import qualified Reflex.FunctorMaybe
import Data.Patch
Expand Down Expand Up @@ -680,14 +684,17 @@ instance (Reflex t, IsString a) => IsString (Behavior t a) where
instance Reflex t => Monad (Behavior t) where
a >>= f = pull $ sample a >>= sample . f
-- Note: it is tempting to write (_ >> b = b); however, this would result in (fail x >> return y) succeeding (returning y), which violates the law that (a >> b = a >>= \_ -> b), since the implementation of (>>=) above actually will fail. Since we can't examine 'Behavior's other than by using sample, I don't think it's possible to write (>>) to be more efficient than the (>>=) above.
return = constant
#if !MIN_VERSION_base(4,13,0)
fail = error "Monad (Behavior t) does not support fail"
#endif

instance (Reflex t, Semigroup a) => Semigroup (Behavior t a) where
a <> b = pull $ liftM2 (<>) (sample a) (sample b)
sconcat = pull . fmap sconcat . mapM sample
stimes n = fmap $ stimes n

instance (Reflex t, Monoid a) => Monoid (Behavior t a) where
mempty = constant mempty
mappend a b = pull $ liftM2 mappend (sample a) (sample b)
mconcat = pull . fmap mconcat . mapM sample

instance (Reflex t, Num a) => Num (Behavior t a) where
Expand All @@ -708,11 +715,6 @@ instance (Num a, Reflex t) => Num (Dynamic t a) where
negate = fmap negate
(-) = liftA2 (-)

instance (Reflex t, Semigroup a) => Semigroup (Behavior t a) where
a <> b = pull $ liftM2 (<>) (sample a) (sample b)
sconcat = pull . fmap sconcat . mapM sample
stimes n = fmap $ stimes n

-- | Alias for 'mapMaybe'
fmapMaybe :: Filterable f => (a -> Maybe b) -> f a -> f b
fmapMaybe = mapMaybe
Expand Down Expand Up @@ -1159,7 +1161,6 @@ instance (Reflex t, Semigroup a) => Semigroup (Dynamic t a) where
instance (Reflex t, Monoid a) => Monoid (Dynamic t a) where
mconcat = distributeListOverDynWith mconcat
mempty = constDyn mempty
mappend = zipDynWith mappend

-- | This function converts a 'DMap' whose elements are 'Dynamic's into a
-- 'Dynamic' 'DMap'. Its implementation is more efficient than doing the same
Expand Down
3 changes: 0 additions & 3 deletions src/Reflex/Dynamic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ import Data.Functor.Compose
import Data.Functor.Misc
import Reflex.Class

import Control.Monad
import Control.Monad.Fix
import Control.Monad.Identity
import Data.Align
Expand All @@ -91,11 +90,9 @@ import qualified Data.Dependent.Map as DMap
import Data.Dependent.Sum (DSum (..))
import Data.GADT.Compare (GCompare (..), GEq (..), GOrdering (..))
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import Data.Kind (Type)
import Data.Map (Map)
import Data.Maybe
import Data.Monoid ((<>))
import Data.These
import Data.Type.Equality ((:~:) (..))

Expand Down
1 change: 0 additions & 1 deletion src/Reflex/Dynamic/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Reflex.Dynamic
import Control.Monad.State
import Data.Data
import Data.Generics
import Data.Monoid ((<>))
import qualified Language.Haskell.Exts as Hs
import qualified Language.Haskell.Meta.Syntax.Translate as Hs
import Language.Haskell.TH
Expand Down
3 changes: 0 additions & 3 deletions src/Reflex/Dynamic/Uniq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module Reflex.Dynamic.Uniq
, alreadyUniqDynamic
) where

import Control.Applicative (Applicative (..))
import GHC.Exts
import Reflex.Class

Expand Down Expand Up @@ -101,5 +100,3 @@ instance Reflex t => Applicative (UniqDynamic t) where

instance Reflex t => Monad (UniqDynamic t) where
UniqDynamic x >>= f = uniqDynamic $ x >>= unUniqDynamic . f
_ >> b = b
return = pure
1 change: 0 additions & 1 deletion src/Reflex/DynamicWriter/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Semigroup (Semigroup(..))
import Data.Some (Some)
import Data.These

Expand Down
1 change: 0 additions & 1 deletion src/Reflex/EventWriter/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module Reflex.EventWriter.Class
) where

import Control.Monad.Reader (ReaderT, lift)
import Data.Semigroup (Semigroup)

import Reflex.Class (Event)

Expand Down
4 changes: 4 additions & 0 deletions src/Reflex/FunctorMaybe.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import Data.Map (Map)
#if !MIN_VERSION_base(4,16,0)
import Data.Semigroup (Option(..))
#endif
#if MIN_VERSION_witherable(0,4,0)
import Witherable
#else
import Data.Witherable
#endif

--TODO: See if there's a better class in the standard libraries already

Expand Down
1 change: 0 additions & 1 deletion src/Reflex/PostBuild/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ runPostBuildT (PostBuildT a) = runReaderT a
-- TODO: Monoid and Semigroup can likely be derived once ReaderT has them.
instance (Monoid a, Applicative m) => Monoid (PostBuildT t m a) where
mempty = pure mempty
mappend = liftA2 mappend

instance (S.Semigroup a, Applicative m) => S.Semigroup (PostBuildT t m a) where
(<>) = liftA2 (S.<>)
Expand Down
1 change: 0 additions & 1 deletion src/Reflex/Profiled.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import Data.List
import Data.Kind (Type)
import Data.Map (Map)
import qualified Data.Map.Strict as Map
import Data.Monoid ((<>))
import Data.Ord
import Data.Profunctor.Unsafe ((#.))
import qualified Data.Semigroup as S
Expand Down
1 change: 0 additions & 1 deletion src/Reflex/Query/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import qualified Data.IntMap as IntMap
import Data.Kind (Type)
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Monoid ((<>))
import qualified Data.Semigroup as S
import Data.Semigroup.Commutative
import Data.Some (Some(Some))
Expand Down
1 change: 0 additions & 1 deletion src/Reflex/Query/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import Data.Ix
import Data.Kind (Type)
import Data.Map.Monoidal (MonoidalMap)
import qualified Data.Map.Monoidal as MonoidalMap
import Data.Semigroup (Semigroup(..))
import Data.Semigroup.Commutative
import Data.Void
import Data.Monoid hiding ((<>))

Check warning on line 42 in src/Reflex/Query/Class.hs

View workflow job for this annotation

GitHub Actions / GHC 8.4.4 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 42 in src/Reflex/Query/Class.hs

View workflow job for this annotation

GitHub Actions / GHC 8.4.4 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 42 in src/Reflex/Query/Class.hs

View workflow job for this annotation

GitHub Actions / GHC 8.4.4 on macos-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 42 in src/Reflex/Query/Class.hs

View workflow job for this annotation

GitHub Actions / GHC 8.4.4 on macos-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 42 in src/Reflex/Query/Class.hs

View workflow job for this annotation

GitHub Actions / GHC 8.4.4 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 42 in src/Reflex/Query/Class.hs

View workflow job for this annotation

GitHub Actions / GHC 8.4.4 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 42 in src/Reflex/Query/Class.hs

View workflow job for this annotation

GitHub Actions / GHC 8.4.4 on macos-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 42 in src/Reflex/Query/Class.hs

View workflow job for this annotation

GitHub Actions / GHC 8.4.4 on macos-latest

The import of ‘Data.Monoid’ is redundant
Expand Down
7 changes: 2 additions & 5 deletions src/Reflex/Requester/Base/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ import qualified Data.IntMap.Strict as IntMap
import Data.Kind (Type)
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Monoid ((<>))
import Data.Proxy
import qualified Data.Semigroup as S
import Data.Some (Some(Some))
import Data.Type.Equality
import Data.Unique.Tag
Expand Down Expand Up @@ -298,10 +296,9 @@ instance PrimMonad m => PrimMonad (RequesterT t request response m) where
-- TODO: Monoid and Semigroup can likely be derived once StateT has them.
instance (Monoid a, Monad m) => Monoid (RequesterT t request response m a) where
mempty = pure mempty
mappend = liftA2 mappend

instance (S.Semigroup a, Monad m) => S.Semigroup (RequesterT t request response m a) where
(<>) = liftA2 (S.<>)
instance (Semigroup a, Monad m) => Semigroup (RequesterT t request response m a) where
(<>) = liftA2 (<>)


-- | Run a 'RequesterT' action. The resulting 'Event' will fire whenever
Expand Down
35 changes: 14 additions & 21 deletions src/Reflex/Spider/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ import Control.Monad.Reader.Class
import Control.Monad.IO.Class
import Control.Monad.ReaderIO
import Control.Monad.Ref
#if !MIN_VERSION_base(4,13,0)
import Control.Monad.Fail (MonadFail)
#endif
import qualified Control.Monad.Fail as MonadFail
import Data.Align
import Data.Coerce
import Data.Dependent.Map (DMap)
import qualified Data.Dependent.Map as DMap
import Data.Dependent.Sum (DSum (..))
import Data.FastMutableIntMap (FastMutableIntMap, PatchIntMap (..))
import Data.FastMutableIntMap (FastMutableIntMap)
import qualified Data.FastMutableIntMap as FastMutableIntMap
import Data.Foldable hiding (concat, elem, sequence_)
import Data.Functor.Constant
Expand All @@ -63,12 +65,15 @@ import qualified Data.IntMap.Strict as IntMap
import Data.IORef
import Data.Kind (Type)
import Data.Maybe hiding (mapMaybe)
import Data.Monoid (mempty, (<>))
import Data.Proxy
import Data.These
import Data.Traversable
import Data.Type.Equality ((:~:)(Refl))
#if MIN_VERSION_witherable(0,4,0)
import Witherable (Filterable, mapMaybe)
#else
import Data.Witherable (Filterable, mapMaybe)
#endif
import GHC.Exts hiding (toList)
import GHC.IORef (IORef (..))
import GHC.Stack
Expand All @@ -93,7 +98,10 @@ import Control.Monad.State hiding (forM, forM_, mapM, mapM_, sequence)
import Data.List.NonEmpty (NonEmpty (..), nonEmpty)
import qualified Data.List.NonEmpty as NonEmpty
import Data.Tree (Forest, Tree (..), drawForest)

#ifdef DEBUG_HIDE_INTERNALS
import Data.List (isPrefixOf)
#endif

import Data.FastWeakBag (FastWeakBag, FastWeakBagTicket)
import qualified Data.FastWeakBag as FastWeakBag
Expand Down Expand Up @@ -992,10 +1000,6 @@ newtype BehaviorM x a = BehaviorM { unBehaviorM :: ReaderIO (BehaviorEnv x) a }
instance Monad (BehaviorM x) where
{-# INLINE (>>=) #-}
BehaviorM x >>= f = BehaviorM $ x >>= unBehaviorM . f
{-# INLINE (>>) #-}
BehaviorM x >> BehaviorM y = BehaviorM $ x >> y
{-# INLINE return #-}
return x = BehaviorM $ return x
#if !MIN_VERSION_base(4,13,0)
{-# INLINE fail #-}
fail s = BehaviorM $ fail s
Expand Down Expand Up @@ -1096,7 +1100,7 @@ heightBagRemove (Height h) b@(HeightBag s c) = heightBagVerify $ case IntMap.loo
_ -> IntMap.insert h (pred old) c

heightBagRemoveMaybe :: Height -> HeightBag -> Maybe HeightBag
heightBagRemoveMaybe (Height h) b@(HeightBag s c) = heightBagVerify . removed <$> IntMap.lookup h c where
heightBagRemoveMaybe (Height h) (HeightBag s c) = heightBagVerify . removed <$> IntMap.lookup h c where
removed old = HeightBag (pred s) $ case old of
0 -> IntMap.delete h c
_ -> IntMap.insert h (pred old) c
Expand Down Expand Up @@ -1471,7 +1475,7 @@ filterStack :: String -> [String] -> [String]
#ifdef DEBUG_HIDE_INTERNALS
filterStack prefix = filter (not . (prefix `isPrefixOf`))
#else
filterStack prefix = id
filterStack _prefix = id
#endif

#ifdef DEBUG_CYCLES
Expand Down Expand Up @@ -2547,12 +2551,8 @@ instance HasSpiderTimeline x => Reflex.Class.MonadHold (SpiderTimeline x) (Spide


instance HasSpiderTimeline x => Monad (Reflex.Class.Dynamic (SpiderTimeline x)) where
{-# INLINE return #-}
return = pure
{-# INLINE (>>=) #-}
x >>= f = SpiderDynamic $ dynamicDynIdentity $ newJoinDyn $ newMapDyn (unSpiderDynamic . f) $ unSpiderDynamic x
{-# INLINE (>>) #-}
(>>) = (*>)
#if !MIN_VERSION_base(4,13,0)
{-# INLINE fail #-}
fail _ = error "Dynamic does not support 'fail'"
Expand Down Expand Up @@ -2833,15 +2833,12 @@ instance MonadAtomicRef (EventM x) where
atomicModifyRef r f = liftIO $ atomicModifyRef r f

-- | The monad for actions that manipulate a Spider timeline identified by @x@
newtype SpiderHost (x :: Type) a = SpiderHost { unSpiderHost :: IO a } deriving (Functor, Applicative, MonadFix, MonadIO, MonadException, MonadAsyncException)
newtype SpiderHost (x :: Type) a = SpiderHost { unSpiderHost :: IO a }
deriving (Functor, Applicative, MonadFix, MonadIO, MonadException, MonadAsyncException)

instance Monad (SpiderHost x) where
{-# INLINABLE (>>=) #-}
SpiderHost x >>= f = SpiderHost $ x >>= unSpiderHost . f
{-# INLINABLE (>>) #-}
SpiderHost x >> SpiderHost y = SpiderHost $ x >> y
{-# INLINABLE return #-}
return x = SpiderHost $ return x
#if !MIN_VERSION_base(4,13,0)
{-# INLINABLE fail #-}
fail = MonadFail.fail
Expand All @@ -2867,10 +2864,6 @@ newtype SpiderHostFrame (x :: Type) a = SpiderHostFrame { runSpiderHostFrame ::
instance Monad (SpiderHostFrame x) where
{-# INLINABLE (>>=) #-}
SpiderHostFrame x >>= f = SpiderHostFrame $ x >>= runSpiderHostFrame . f
{-# INLINABLE (>>) #-}
SpiderHostFrame x >> SpiderHostFrame y = SpiderHostFrame $ x >> y
{-# INLINABLE return #-}
return x = SpiderHostFrame $ return x
#if !MIN_VERSION_base(4,13,0)
{-# INLINABLE fail #-}
fail s = SpiderHostFrame $ fail s
Expand Down
1 change: 0 additions & 1 deletion src/Reflex/Time.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import Control.Monad.IO.Class
import Data.Align
import Data.Data (Data)
import Data.Fixed
import Data.Semigroup (Semigroup(..))
import Data.Sequence (Seq, (|>))
import qualified Data.Sequence as Seq
import Data.These
Expand Down
1 change: 0 additions & 1 deletion src/Reflex/TriggerEvent/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Control.Monad.Ref
import Data.Coerce
import Data.Dependent.Sum
import Data.IORef
import Data.Monoid ((<>))
import qualified Data.Semigroup as S
import Reflex.Class
import Reflex.Adjustable.Class
Expand Down

0 comments on commit 7efee20

Please sign in to comment.