module GHC.Data.Strict (
Maybe(Nothing, Just),
fromMaybe,
Pair(And),
) where
import GHC.Prelude hiding (Maybe(..), Either(..))
import Control.Applicative
import Data.Semigroup
import Data.Data
data Maybe a = Nothing | Just !a
deriving (Eq, Ord, Show, Functor, Foldable, Traversable, Data)
fromMaybe :: a -> Maybe a -> a
fromMaybe d Nothing = d
fromMaybe _ (Just x) = x
apMaybe :: Maybe (a -> b) -> Maybe a -> Maybe b
apMaybe (Just f) (Just x) = Just (f x)
apMaybe _ _ = Nothing
altMaybe :: Maybe a -> Maybe a -> Maybe a
altMaybe Nothing r = r
altMaybe l _ = l
instance Semigroup a => Semigroup (Maybe a) where
Nothing <> b = b
a <> Nothing = a
Just a <> Just b = Just (a <> b)
instance Semigroup a => Monoid (Maybe a) where
mempty = Nothing
instance Applicative Maybe where
pure = Just
(<*>) = apMaybe
instance Alternative Maybe where
empty = Nothing
(<|>) = altMaybe
data Pair a b = !a `And` !b
deriving (Eq, Ord, Show, Functor, Foldable, Traversable, Data)