|
1 | 1 | module Data.Maybe where |
2 | 2 |
|
| 3 | +import Prelude |
| 4 | + |
3 | 5 | import Control.Alt (class Alt) |
4 | 6 | import Control.Alternative (class Alternative) |
5 | | -import Control.Applicative (class Applicative) |
6 | | -import Control.Apply (class Apply) |
7 | | -import Control.Bind (class Bind) |
8 | 7 | import Control.Extend (class Extend) |
9 | | -import Control.Monad (class Monad) |
10 | 8 | import Control.MonadZero (class MonadZero) |
11 | 9 | import Control.Plus (class Plus) |
12 | 10 |
|
13 | | -import Data.Bounded (class Bounded, top) |
14 | | -import Data.Eq (class Eq, (==)) |
15 | | -import Data.Function (const, id) |
16 | | -import Data.Functor (class Functor, (<$>)) |
17 | 11 | import Data.Functor.Invariant (class Invariant, imapF) |
18 | 12 | import Data.Monoid (class Monoid) |
19 | | -import Data.Ord (class Ord, compare) |
20 | | -import Data.Ordering (Ordering(..)) |
21 | | -import Data.Semigroup (class Semigroup, (<>)) |
22 | | -import Data.Show (class Show, show) |
23 | | -import Data.Unit (Unit, unit) |
24 | 13 |
|
25 | 14 | -- | The `Maybe` type is used to represent optional values and can be seen as |
26 | 15 | -- | something like a type-safe `null`, where `Nothing` is `null` and `Just x` |
@@ -193,21 +182,14 @@ instance monoidMaybe :: Semigroup a => Monoid (Maybe a) where |
193 | 182 | -- | The `Eq` instance allows `Maybe` values to be checked for equality with |
194 | 183 | -- | `==` and inequality with `/=` whenever there is an `Eq` instance for the |
195 | 184 | -- | type the `Maybe` contains. |
196 | | -instance eqMaybe :: Eq a => Eq (Maybe a) where |
197 | | - eq Nothing Nothing = true |
198 | | - eq (Just a1) (Just a2) = a1 == a2 |
199 | | - eq _ _ = false |
| 185 | +derive instance eqMaybe :: Eq a => Eq (Maybe a) |
200 | 186 |
|
201 | 187 | -- | The `Ord` instance allows `Maybe` values to be compared with |
202 | 188 | -- | `compare`, `>`, `>=`, `<` and `<=` whenever there is an `Ord` instance for |
203 | 189 | -- | the type the `Maybe` contains. |
204 | 190 | -- | |
205 | 191 | -- | `Nothing` is considered to be less than any `Just` value. |
206 | | -instance ordMaybe :: Ord a => Ord (Maybe a) where |
207 | | - compare (Just x) (Just y) = compare x y |
208 | | - compare Nothing Nothing = EQ |
209 | | - compare Nothing _ = LT |
210 | | - compare _ Nothing = GT |
| 192 | +derive instance ordMaybe :: Ord a => Ord (Maybe a) |
211 | 193 |
|
212 | 194 | instance boundedMaybe :: Bounded a => Bounded (Maybe a) where |
213 | 195 | top = Just top |
|
0 commit comments