Skip to content

Commit ff5836d

Browse files
committed
Use newtypes where possible
1 parent cfd9c4b commit ff5836d

File tree

10 files changed

+35
-35
lines changed

10 files changed

+35
-35
lines changed

docs/Module.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
### Types
2929

30-
data ContT r m a where
30+
newtype ContT r m a where
3131
ContT :: (a -> m r) -> m r -> ContT r m a
3232

3333

@@ -101,7 +101,7 @@
101101

102102
### Types
103103

104-
data ErrorT e m a where
104+
newtype ErrorT e m a where
105105
ErrorT :: m (Either e a) -> ErrorT e m a
106106

107107

@@ -187,7 +187,7 @@
187187

188188
### Types
189189

190-
data Identity a where
190+
newtype Identity a where
191191
Identity :: a -> Identity a
192192

193193

@@ -213,7 +213,7 @@
213213

214214
### Types
215215

216-
data MaybeT m a where
216+
newtype MaybeT m a where
217217
MaybeT :: m (Maybe a) -> MaybeT m a
218218

219219

@@ -317,7 +317,7 @@
317317

318318
### Types
319319

320-
data RWST r w s m a where
320+
newtype RWST r w s m a where
321321
RWST :: r -> s -> m (See s a w) -> RWST r w s m a
322322

323323
type See s a w = { log :: w, result :: a, state :: s }
@@ -404,7 +404,7 @@
404404

405405
### Types
406406

407-
data ReaderT r m a where
407+
newtype ReaderT r m a where
408408
ReaderT :: r -> m a -> ReaderT r m a
409409

410410

@@ -500,7 +500,7 @@
500500

501501
### Types
502502

503-
data StateT s m a where
503+
newtype StateT s m a where
504504
StateT :: s -> m (Tuple a s) -> StateT s m a
505505

506506

@@ -548,7 +548,7 @@
548548

549549
### Types
550550

551-
data Delay a where
551+
newtype Delay a where
552552
Delay :: Unit -> a -> Delay a
553553

554554
type Trampoline a = Free Delay a
@@ -636,7 +636,7 @@
636636

637637
### Types
638638

639-
data WriterT w m a where
639+
newtype WriterT w m a where
640640
WriterT :: m (Tuple a w) -> WriterT w m a
641641

642642

src/Control/Monad/Cont/Trans.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Control.Monad.Cont.Trans where
33
import Prelude
44
import Control.Monad.Trans
55

6-
data ContT r m a = ContT ((a -> m r) -> m r)
6+
newtype ContT r m a = ContT ((a -> m r) -> m r)
77

88
runContT :: forall r m a. ContT r m a -> (a -> m r) -> m r
99
runContT (ContT f) k = f k

src/Control/Monad/Error/Trans.purs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Data.Either
77
import Data.Monoid
88
import Data.Tuple
99

10-
data ErrorT e m a = ErrorT (m (Either e a))
10+
newtype ErrorT e m a = ErrorT (m (Either e a))
1111

1212
runErrorT :: forall e m a. ErrorT e m a -> m (Either e a)
1313
runErrorT (ErrorT x) = x
@@ -17,7 +17,7 @@ mapErrorT f m = ErrorT $ f (runErrorT m)
1717

1818
instance functorErrorT :: (Functor m) => Functor (ErrorT e m) where
1919
(<$>) f = ErrorT <<< (<$>) ((<$>) f) <<< runErrorT
20-
20+
2121
instance applyErrorT :: (Functor m, Monad m) => Apply (ErrorT e m) where
2222
(<*>) f v = ErrorT $ do
2323
mf <- runErrorT f
@@ -28,10 +28,10 @@ instance applyErrorT :: (Functor m, Monad m) => Apply (ErrorT e m) where
2828
return case mv of
2929
Left e -> Left e
3030
Right x -> Right (k x)
31-
31+
3232
instance applicativeErrorT :: (Functor m, Monad m) => Applicative (ErrorT e m) where
3333
pure a = ErrorT $ pure $ Right a
34-
34+
3535
instance alternativeErrorT :: (Monad m, Error e) => Alternative (ErrorT e m) where
3636
empty = ErrorT (return (Left $ strMsg "No alternative"))
3737
(<|>) x y = ErrorT $ runErrorT x >>= \e -> case e of
@@ -44,9 +44,9 @@ instance bindErrorT :: (Monad m, Error e) => Bind (ErrorT e m) where
4444
case a of
4545
Left e -> return $ Left e
4646
Right x -> runErrorT (f x)
47-
47+
4848
instance monadErrorT :: (Monad m, Error e) => Monad (ErrorT e m)
49-
49+
5050
instance monadTransErrorT :: (Error e) => MonadTrans (ErrorT e) where
5151
lift m = ErrorT $ do
5252
a <- m

src/Control/Monad/Identity.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ module Control.Monad.Identity where
22

33
import Prelude
44

5-
data Identity a = Identity a
5+
newtype Identity a = Identity a
66

77
runIdentity :: forall a. Identity a -> a
88
runIdentity (Identity x) = x
99

1010
instance functorIdentity :: Functor Identity where
1111
(<$>) f m = Identity $ f $ runIdentity m
12-
12+
1313
instance applyIdentity :: Apply Identity where
1414
(<*>) (Identity f) (Identity x) = Identity $ f x
15-
15+
1616
instance applicativeIdentity :: Applicative Identity where
1717
pure = Identity
1818

1919
instance bindIdentity :: Bind Identity where
2020
(>>=) m f = f $ runIdentity m
21-
21+
2222
instance monadIdentity :: Monad Identity

src/Control/Monad/Maybe/Trans.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Data.Either
77
import Data.Maybe
88
import Data.Tuple
99

10-
data MaybeT m a = MaybeT (m (Maybe a))
10+
newtype MaybeT m a = MaybeT (m (Maybe a))
1111

1212
instance functorMaybeT :: (Monad m) => Functor (MaybeT m) where
1313
(<$>) = liftA1

src/Control/Monad/RWS/Trans.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ type See s a w =
99
, result :: a
1010
, log :: w
1111
}
12-
12+
1313
mkSee :: forall s a w. (Monoid w) => s -> a -> w -> See s a w
1414
mkSee s a w = { state: s, result: a, log: w }
1515

16-
data RWST r w s m a = RWST (r -> s -> m (See s a w))
16+
newtype RWST r w s m a = RWST (r -> s -> m (See s a w))
1717

1818
runRWST :: forall r w s m a. RWST r w s m a -> r -> s -> m (See s a w)
1919
runRWST (RWST x) = x

src/Control/Monad/Reader/Trans.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Control.Monad.Reader.Trans where
33
import Prelude
44
import Control.Monad.Trans
55

6-
data ReaderT r m a = ReaderT (r -> m a)
6+
newtype ReaderT r m a = ReaderT (r -> m a)
77

88
runReaderT :: forall r m a. ReaderT r m a -> (r -> m a)
99
runReaderT (ReaderT x) = x
@@ -19,13 +19,13 @@ liftReaderT m = ReaderT (const m)
1919

2020
instance functorReaderT :: (Functor m) => Functor (ReaderT r m) where
2121
(<$>) f = mapReaderT $ (<$>) f
22-
22+
2323
instance applyReaderT :: (Applicative m) => Apply (ReaderT r m) where
2424
(<*>) f v = ReaderT \r -> runReaderT f r <*> runReaderT v r
25-
25+
2626
instance applicativeReaderT :: (Applicative m) => Applicative (ReaderT r m) where
2727
pure = liftReaderT <<< pure
28-
28+
2929
instance alternativeReaderT :: (Alternative m) => Alternative (ReaderT r m) where
3030
empty = liftReaderT empty
3131
(<|>) m n = ReaderT \r -> runReaderT m r <|> runReaderT n r

src/Control/Monad/State/Trans.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Prelude
44
import Control.Monad.Trans
55
import Data.Tuple
66

7-
data StateT s m a = StateT (s -> m (Tuple a s))
7+
newtype StateT s m a = StateT (s -> m (Tuple a s))
88

99
runStateT :: forall s m a. StateT s m a -> s -> m (Tuple a s)
1010
runStateT (StateT s) = s
@@ -23,13 +23,13 @@ withStateT f s = StateT $ runStateT s <<< f
2323

2424
instance functorStateT :: (Monad m) => Functor (StateT s m) where
2525
(<$>) = liftM1
26-
26+
2727
instance applyStateT :: (Monad m) => Apply (StateT s m) where
2828
(<*>) = ap
2929

3030
instance applicativeStateT :: (Monad m) => Applicative (StateT s m) where
3131
pure a = StateT $ \s -> return $ Tuple a s
32-
32+
3333
instance alternativeStateT :: (Alternative m) => Alternative (StateT s m) where
3434
empty = StateT $ \_ -> empty
3535
(<|>) x y = StateT $ \s -> runStateT x s <|> runStateT y s
@@ -38,7 +38,7 @@ instance bindStateT :: (Monad m) => Bind (StateT s m) where
3838
(>>=) (StateT x) f = StateT \s -> do
3939
Tuple v s' <- x s
4040
runStateT (f v) s'
41-
41+
4242
instance monadStateT :: (Monad m) => Monad (StateT s m)
4343

4444
instance monadTransStateT :: MonadTrans (StateT s) where

src/Control/Monad/Trampoline.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Control.Monad.Trampoline where
22

33
import Control.Monad.Free
44

5-
data Delay a = Delay (Unit -> a)
5+
newtype Delay a = Delay (Unit -> a)
66

77
instance delayFunctor :: Functor Delay where
88
(<$>) f (Delay g) = Delay (const (f (g unit)))

src/Control/Monad/Writer/Trans.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Control.Monad.Trans
55
import Data.Monoid
66
import Data.Tuple
77

8-
data WriterT w m a = WriterT (m (Tuple a w))
8+
newtype WriterT w m a = WriterT (m (Tuple a w))
99

1010
runWriterT :: forall w m a. WriterT w m a -> m (Tuple a w)
1111
runWriterT (WriterT x) = x
@@ -15,12 +15,12 @@ mapWriterT f m = WriterT $ f (runWriterT m)
1515

1616
instance functorWriterT :: (Functor m) => Functor (WriterT w m) where
1717
(<$>) f = mapWriterT $ (<$>) \(Tuple a w) -> Tuple (f a) w
18-
18+
1919
instance applyWriterT :: (Monoid w, Functor m, Applicative m) => Apply (WriterT w m) where
2020
(<*>) f v = WriterT $
2121
let k (Tuple a w) (Tuple b w') = Tuple (a b) (w <> w')
2222
in k <$> (runWriterT f) <*> (runWriterT v)
23-
23+
2424
instance applicativeWriterT :: (Monoid w, Functor m, Applicative m) => Applicative (WriterT w m) where
2525
pure a = WriterT $ pure $ Tuple a mempty
2626

0 commit comments

Comments
 (0)