    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Data.Strict.Maybe
    -- Copyright   :  (c) 2006-2007 Roman Leshchinskiy
    -- License     :  BSD-style (see the file LICENSE)
    --
    -- Maintainer  :  Roman Leshchinskiy <rl@cse.unsw.edu.au>
    -- Stability   :  experimental
    -- Portability :  portable
    --
    -- Strict @Maybe@.
    --
    -- Same as the standard Haskell @Maybe@, but @Just _|_ = _|_@
    --
    -- Note that strict @Maybe@ is not a monad since
    -- @ return _|_ >>= f = _|_ @
    -- which is not necessarily the same as @f _|_@.
    --
    -----------------------------------------------------------------------------

    module Data.Strict.Maybe (
        Maybe(..)
      , isJust
      , isNothing
      , fromJust
      , fromMaybe
      , maybe
    ) where

    import Prelude hiding( Maybe(..), maybe )

    -- | The type of strict optional values.
    data Maybe a = Nothing | Just !a deriving(Maybe a -> Maybe a -> Bool
    (Maybe a -> Maybe a -> Bool)
    -> (Maybe a -> Maybe a -> Bool) -> Eq (Maybe a)
    forall a. Eq a => Maybe a -> Maybe a -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: Maybe a -> Maybe a -> Bool
    $c/= :: forall a. Eq a => Maybe a -> Maybe a -> Bool
    == :: Maybe a -> Maybe a -> Bool
    $c== :: forall a. Eq a => Maybe a -> Maybe a -> Bool
    Eq, Eq (Maybe a)
    Eq (Maybe a) =>
    (Maybe a -> Maybe a -> Ordering)
    -> (Maybe a -> Maybe a -> Bool)
    -> (Maybe a -> Maybe a -> Bool)
    -> (Maybe a -> Maybe a -> Bool)
    -> (Maybe a -> Maybe a -> Bool)
    -> (Maybe a -> Maybe a -> Maybe a)
    -> (Maybe a -> Maybe a -> Maybe a)
    -> Ord (Maybe a)
    Maybe a -> Maybe a -> Bool
    Maybe a -> Maybe a -> Ordering
    Maybe a -> Maybe a -> Maybe a
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall a. Ord a => Eq (Maybe a)
    forall a. Ord a => Maybe a -> Maybe a -> Bool
    forall a. Ord a => Maybe a -> Maybe a -> Ordering
    forall a. Ord a => Maybe a -> Maybe a -> Maybe a
    min :: Maybe a -> Maybe a -> Maybe a
    $cmin :: forall a. Ord a => Maybe a -> Maybe a -> Maybe a
    max :: Maybe a -> Maybe a -> Maybe a
    $cmax :: forall a. Ord a => Maybe a -> Maybe a -> Maybe a
    >= :: Maybe a -> Maybe a -> Bool
    $c>= :: forall a. Ord a => Maybe a -> Maybe a -> Bool
    > :: Maybe a -> Maybe a -> Bool
    $c> :: forall a. Ord a => Maybe a -> Maybe a -> Bool
    <= :: Maybe a -> Maybe a -> Bool
    $c<= :: forall a. Ord a => Maybe a -> Maybe a -> Bool
    < :: Maybe a -> Maybe a -> Bool
    $c< :: forall a. Ord a => Maybe a -> Maybe a -> Bool
    compare :: Maybe a -> Maybe a -> Ordering
    $ccompare :: forall a. Ord a => Maybe a -> Maybe a -> Ordering
    $cp1Ord :: forall a. Ord a => Eq (Maybe a)
    Ord, Int -> Maybe a -> ShowS
    [Maybe a] -> ShowS
    Maybe a -> String
    (Int -> Maybe a -> ShowS)
    -> (Maybe a -> String) -> ([Maybe a] -> ShowS) -> Show (Maybe a)
    forall a. Show a => Int -> Maybe a -> ShowS
    forall a. Show a => [Maybe a] -> ShowS
    forall a. Show a => Maybe a -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [Maybe a] -> ShowS
    $cshowList :: forall a. Show a => [Maybe a] -> ShowS
    show :: Maybe a -> String
    $cshow :: forall a. Show a => Maybe a -> String
    showsPrec :: Int -> Maybe a -> ShowS
    $cshowsPrec :: forall a. Show a => Int -> Maybe a -> ShowS
    Show, ReadPrec [Maybe a]
    ReadPrec (Maybe a)
    Int -> ReadS (Maybe a)
    ReadS [Maybe a]
    (Int -> ReadS (Maybe a))
    -> ReadS [Maybe a]
    -> ReadPrec (Maybe a)
    -> ReadPrec [Maybe a]
    -> Read (Maybe a)
    forall a. Read a => ReadPrec [Maybe a]
    forall a. Read a => ReadPrec (Maybe a)
    forall a. Read a => Int -> ReadS (Maybe a)
    forall a. Read a => ReadS [Maybe a]
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    readListPrec :: ReadPrec [Maybe a]
    $creadListPrec :: forall a. Read a => ReadPrec [Maybe a]
    readPrec :: ReadPrec (Maybe a)
    $creadPrec :: forall a. Read a => ReadPrec (Maybe a)
    readList :: ReadS [Maybe a]
    $creadList :: forall a. Read a => ReadS [Maybe a]
    readsPrec :: Int -> ReadS (Maybe a)
    $creadsPrec :: forall a. Read a => Int -> ReadS (Maybe a)
    Read)

    instance Functor Maybe where
      fmap :: (a -> b) -> Maybe a -> Maybe b
    fmap _ Nothing  = Maybe b
    forall a. Maybe a
    Nothing
      fmap f :: a -> b
    f (Just x :: a
    x) = b -> Maybe b
    forall a. a -> Maybe a
    Just (a -> b
    f a
    x)

    -- | Yields 'True' iff the argument is of the form @Just _@.
    isJust :: Maybe a -> Bool
    isJust :: Maybe a -> Bool
    isJust Nothing = Bool
    False
    isJust _       = Bool
    True

    -- | Yields 'True' iff the argument is 'Nothing'.
    isNothing :: Maybe a -> Bool
    isNothing :: Maybe a -> Bool
    isNothing Nothing = Bool
    True
    isNothing _       = Bool
    False

    -- | Extracts the element out of a 'Just' and throws an error if the argument
    -- is 'Nothing'.
    fromJust :: Maybe a -> a
    fromJust :: Maybe a -> a
    fromJust Nothing  = String -> a
    forall a. HasCallStack => String -> a
    error "Data.Strict.Maybe.fromJust: Nothing"
    fromJust (Just x :: a
    x) = a
    x

    -- | Given a default value and a 'Maybe', yield the default value if the
    -- 'Maybe' argument is 'Nothing' and extract the value out of the 'Just'
    -- otherwise.
    fromMaybe :: a -> Maybe a -> a
    fromMaybe :: a -> Maybe a -> a
    fromMaybe x :: a
    x Nothing  = a
    x
    fromMaybe _ (Just y :: a
    y) = a
    y

    -- | Given a default value, a function and a 'Maybe' value, yields the default
    -- value if the 'Maybe' value is 'Nothing' and applies the function to the
    -- value stored in the 'Just' otherwise.
    maybe :: b -> (a -> b) -> Maybe a -> b
    maybe :: b -> (a -> b) -> Maybe a -> b
    maybe x :: b
    x _ Nothing  = b
    x
    maybe _ f :: a -> b
    f (Just y :: a
    y) = a -> b
    f a
    y