on master help sign in
moved Monad instances to after the Functor and Applicative ones.
934e096startling
lib/Prelude.idr+33−33
@@ -68,39 +68,6 @@ instance Show a => Show (Maybe a) where
68 show Nothing = "Nothing"
68 show Nothing = "Nothing"
69 show (Just x) = "Just " ++ show x
69 show (Just x) = "Just " ++ show x
70
70
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−
104---- Functor instances
71---- Functor instances
105
72
106instance Functor Maybe where
73instance Functor Maybe where
@@ -134,6 +101,39 @@ instance Applicative List where
134
101
135 fs <$> vs = concatMap (\f => map f vs) fs
102 fs <$> vs = concatMap (\f => map f vs) fs
136
103
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+
137---- some mathematical operations
137---- some mathematical operations
138
138
139%include "math.h"
139%include "math.h"