1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
{- |
Module : Data.MaybeLike.Instances
Copyright : (c) Eduard Sergeev 2013
License : BSD-style (see the file LICENSE)
Maintainer : eduard.sergeev@gmail.com
Stability : experimental
Portability : non-portable (multi-param classes, functional dependencies)
Defines default instances of `MaybeLike` for most primitive "Unboxed" types
-}
{-# LANGUAGE NoImplicitPrelude, MultiParamTypeClasses,
FlexibleContexts, FlexibleInstances #-}
module Data.MaybeLike.Instances
(
module Data.MaybeLike
) where
import Data.Eq ((==))
import Prelude (Bounded(maxBound), (/), isNaN)
import Prelude (Float, Double)
import Data.Char
import Data.Int
import Data.Word
import qualified Data.Maybe as M
import Data.MaybeLike
instance MaybeLike (M.Maybe a) a where
{-# INLINE nothing #-}
nothing = M.Nothing
{-# INLINE isNothing #-}
isNothing = M.isNothing
{-# INLINE just #-}
just = M.Just
{-# INLINE fromJust #-}
fromJust = M.fromJust
instance MaybeLike Char Char where
{-# INLINE nothing #-}
nothing = maxBound
{-# INLINE isNothing #-}
isNothing v = v == maxBound
{-# INLINE just #-}
just v = v
{-# INLINE fromJust #-}
fromJust v = v
instance MaybeLike Int Int where
{-# INLINE nothing #-}
nothing = maxBound
{-# INLINE isNothing #-}
isNothing v = v == maxBound
{-# INLINE just #-}
just v = v
{-# INLINE fromJust #-}
fromJust v = v
instance MaybeLike Int8 Int8 where
{-# INLINE nothing #-}
nothing = maxBound
{-# INLINE isNothing #-}
isNothing v = v == maxBound
{-# INLINE just #-}
just v = v
{-# INLINE fromJust #-}
fromJust v = v
instance MaybeLike Int16 Int16 where
{-# INLINE nothing #-}
nothing = maxBound
{-# INLINE isNothing #-}
isNothing v = v == maxBound
{-# INLINE just #-}
just v = v
{-# INLINE fromJust #-}
fromJust v = v
instance MaybeLike Int32 Int32 where
{-# INLINE nothing #-}
nothing = maxBound
{-# INLINE isNothing #-}
isNothing v = v == maxBound
{-# INLINE just #-}
just v = v
{-# INLINE fromJust #-}
fromJust v = v
instance MaybeLike Int64 Int64 where
{-# INLINE nothing #-}
nothing = maxBound
{-# INLINE isNothing #-}
isNothing v = v == maxBound
{-# INLINE just #-}
just v = v
{-# INLINE fromJust #-}
fromJust v = v
instance MaybeLike Word Word where
{-# INLINE nothing #-}
nothing = maxBound
{-# INLINE isNothing #-}
isNothing v = v == maxBound
{-# INLINE just #-}
just v = v
{-# INLINE fromJust #-}
fromJust v = v
instance MaybeLike Word8 Word8 where
{-# INLINE nothing #-}
nothing = maxBound
{-# INLINE isNothing #-}
isNothing v = v == maxBound
{-# INLINE just #-}
just v = v
{-# INLINE fromJust #-}
fromJust v = v
instance MaybeLike Word16 Word16 where
{-# INLINE nothing #-}
nothing = maxBound
{-# INLINE isNothing #-}
isNothing v = v == maxBound
{-# INLINE just #-}
just v = v
{-# INLINE fromJust #-}
fromJust v = v
instance MaybeLike Word32 Word32 where
{-# INLINE nothing #-}
nothing = maxBound
{-# INLINE isNothing #-}
isNothing v = v == maxBound
{-# INLINE just #-}
just v = v
{-# INLINE fromJust #-}
fromJust v = v
instance MaybeLike Word64 Word64 where
{-# INLINE nothing #-}
nothing = maxBound
{-# INLINE isNothing #-}
isNothing v = v == maxBound
{-# INLINE just #-}
just v = v
{-# INLINE fromJust #-}
fromJust v = v
instance MaybeLike Float Float where
{-# INLINE nothing #-}
nothing = 0/0
{-# INLINE isNothing #-}
isNothing = isNaN
{-# INLINE just #-}
just v = v
{-# INLINE fromJust #-}
fromJust v = v
instance MaybeLike Double Double where
{-# INLINE nothing #-}
nothing = 0/0
{-# INLINE isNothing #-}
isNothing = isNaN
{-# INLINE just #-}
just v = v
{-# INLINE fromJust #-}
fromJust v = v
|