Skip to content

Commit 318bca7

Browse files
committed
canonicalise Monad instances
1 parent 4634081 commit 318bca7

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

Data/Graph.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ chop (Node v ts : us)
295295
newtype SetM s a = SetM { runSetM :: STArray s Vertex Bool -> ST s a }
296296

297297
instance Monad (SetM s) where
298-
return x = SetM $ const (return x)
298+
return = pure
299299
{-# INLINE return #-}
300300
SetM v >>= f = SetM $ \s -> do { x <- v s; runSetM (f x) s }
301301
{-# INLINE (>>=) #-}

Data/Sequence.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ instance NFData a => NFData (Seq a) where
267267
rnf (Seq xs) = rnf xs
268268

269269
instance Monad Seq where
270-
return = singleton
270+
return = pure
271271
xs >>= f = foldl' add empty xs
272272
where add ys x = ys >< f x
273273
(>>) = (*>)
@@ -861,12 +861,13 @@ instance Functor (State s) where
861861
instance Monad (State s) where
862862
{-# INLINE return #-}
863863
{-# INLINE (>>=) #-}
864-
return x = State $ \ s -> (s, x)
864+
return = pure
865865
m >>= k = State $ \ s -> case runState m s of
866866
(s', x) -> runState (k x) s'
867867

868868
instance Applicative (State s) where
869-
pure = return
869+
{-# INLINE pure #-}
870+
pure x = State $ \ s -> (s, x)
870871
(<*>) = ap
871872

872873
execState :: State s a -> s -> a

Data/Tree.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ instance Applicative Tree where
9292
Node (f x) (map (f <$>) txs ++ map (<*> tx) tfs)
9393

9494
instance Monad Tree where
95-
return x = Node x []
95+
return = pure
9696
Node x ts >>= f = Node x' (ts' ++ map (>>= f) ts)
9797
where Node x' ts' = f x
9898

0 commit comments

Comments
 (0)