on master help sign in
moved Monad instances to after the Functor and Applicative ones.

This is required for those Monad instances to be valid, because Applicative is now a superclass of Monad.

commit934e096ff036371350b017e659650fe8ba6b863b authorstartling <tdixon51793@gmail.com> dateMon 19 Nov 2012, 10:29 (14 years ago) parente876e68
1 file changed+33−33
lib/Prelude.idr+33−33
lib/Prelude.idr+33−33
@@ -68,39 +68,6 @@ instance Show a => Show (Maybe a) where
6868 show Nothing = "Nothing"
6969 show (Just x) = "Just " ++ show x
7070
71−---- Monad instances
72−
73−instance Monad IO where
74− return t = io_return t
75− b >>= k = io_bind b k
76−
77−instance Monad Maybe where
78− return t = Just t
79−
80− Nothing >>= k = Nothing
81− (Just x) >>= k = k x
82−
83−instance MonadPlus Maybe where
84− mzero = Nothing
85−
86− mplus (Just x) _ = Just x
87− mplus Nothing (Just y) = Just y
88− mplus Nothing Nothing = Nothing
89−
90−instance Monad (Either e) where
91− return = Right
92−
93− (Left n) >>= _ = Left n
94− (Right r) >>= f = f r
95−
96−instance Monad List where
97− return x = [x]
98− m >>= f = concatMap f m
99−
100−instance MonadPlus List where
101− mzero = []
102− mplus = (++)
103−
10471---- Functor instances
10572
10673instance Functor Maybe where
@@ -134,6 +101,39 @@ instance Applicative List where
134101
135102 fs <$> vs = concatMap (\f => map f vs) fs
136103
104+---- Monad instances
105+
106+instance Monad IO where
107+ return t = io_return t
108+ b >>= k = io_bind b k
109+
110+instance Monad Maybe where
111+ return t = Just t
112+
113+ Nothing >>= k = Nothing
114+ (Just x) >>= k = k x
115+
116+instance MonadPlus Maybe where
117+ mzero = Nothing
118+
119+ mplus (Just x) _ = Just x
120+ mplus Nothing (Just y) = Just y
121+ mplus Nothing Nothing = Nothing
122+
123+instance Monad (Either e) where
124+ return = Right
125+
126+ (Left n) >>= _ = Left n
127+ (Right r) >>= f = f r
128+
129+instance Monad List where
130+ return x = [x]
131+ m >>= f = concatMap f m
132+
133+instance MonadPlus List where
134+ mzero = []
135+ mplus = (++)
136+
137137---- some mathematical operations
138138
139139%include "math.h"