A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://hackage.haskell.org/packages/archive/base/4.6.0.0/doc/html/src/Data-Maybe.html below:

Data/Maybe.hs


















module Data.Maybe
   (
     Maybe(Nothing,Just)
                        

   , maybe              

   , isJust             
   , isNothing          
   , fromJust           
   , fromMaybe          
   , listToMaybe        
   , maybeToList        
   , catMaybes          
   , mapMaybe           
   ) where

#ifdef __GLASGOW_HASKELL__
import GHC.Base
#endif

#ifdef __NHC__
import Prelude
import Prelude (Maybe(..), maybe)
import Maybe
    ( isJust
    , isNothing
    , fromJust
    , fromMaybe
    , listToMaybe
    , maybeToList
    , catMaybes
    , mapMaybe
    )
#else

#ifndef __HUGS__













data  Maybe a  =  Nothing | Just a
  deriving (Eq, Ord)

instance  Functor Maybe  where
    fmap _ Nothing       = Nothing
    fmap f (Just a)      = Just (f a)

instance  Monad Maybe  where
    (Just x) >>= k      = k x
    Nothing  >>= _      = Nothing

    (Just _) >>  k      = k
    Nothing  >>  _      = Nothing

    return              = Just
    fail _              = Nothing








maybe :: b -> (a -> b) -> Maybe a -> b
maybe n _ Nothing  = n
maybe _ f (Just x) = f x
#endif  /* __HUGS__ */



isJust         :: Maybe a -> Bool
isJust Nothing = False
isJust _       = True


isNothing         :: Maybe a -> Bool
isNothing Nothing = True
isNothing _       = False



fromJust          :: Maybe a -> a
fromJust Nothing  = error "Maybe.fromJust: Nothing" 
fromJust (Just x) = x




fromMaybe     :: a -> Maybe a -> a
fromMaybe d x = case x of {Nothing -> d;Just v  -> v}



maybeToList            :: Maybe a -> [a]
maybeToList  Nothing   = []
maybeToList  (Just x)  = [x]



listToMaybe           :: [a] -> Maybe a
listToMaybe []        =  Nothing
listToMaybe (a:_)     =  Just a



catMaybes              :: [Maybe a] -> [a]
catMaybes ls = [x | Just x <- ls]






mapMaybe          :: (a -> Maybe b) -> [a] -> [b]
mapMaybe _ []     = []
mapMaybe f (x:xs) =
 let rs = mapMaybe f xs in
 case f x of
  Nothing -> rs
  Just r  -> r:rs

#endif /* else not __NHC__ */


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4