Hoogle Search

Within LTS Haskell 24.39 (ghc-9.10.3)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. listToMaybe :: [a] -> Maybe a

    protolude Protolude

    The listToMaybe function returns Nothing on an empty list or Just a where a is the first element of the list.

    Examples

    Basic usage:
    >>> listToMaybe []
    Nothing
    
    >>> listToMaybe [9]
    Just 9
    
    >>> listToMaybe [1,2,3]
    Just 1
    
    Composing maybeToList with listToMaybe should be the identity on singleton/empty lists:
    >>> maybeToList $ listToMaybe [5]
    [5]
    
    >>> maybeToList $ listToMaybe []
    []
    
    But not on lists with more than one element:
    >>> maybeToList $ listToMaybe [1,2,3]
    [1]
    

  2. mapMaybe :: (a -> Maybe b) -> [a] -> [b]

    protolude Protolude

    The mapMaybe function is a version of map which can throw out elements. In particular, the functional argument returns something of type Maybe b. If this is Nothing, no element is added on to the result list. If it is Just b, then b is included in the result list.

    Examples

    Using mapMaybe f x is a shortcut for catMaybes $ map f x in most cases:
    >>> import GHC.Internal.Text.Read ( readMaybe )
    
    >>> let readMaybeInt = readMaybe :: String -> Maybe Int
    
    >>> mapMaybe readMaybeInt ["1", "Foo", "3"]
    [1,3]
    
    >>> catMaybes $ map readMaybeInt ["1", "Foo", "3"]
    [1,3]
    
    If we map the Just constructor, the entire list should be returned:
    >>> mapMaybe Just [1,2,3]
    [1,2,3]
    

  3. readMaybe :: (Read b, StringConv a String) => a -> Maybe b

    protolude Protolude

    Parse a string using the Read instance. Succeeds if there is exactly one valid result.

    >>> readMaybe ("123" :: Text) :: Maybe Int
    Just 123
    
    >>> readMaybe ("hello" :: Text) :: Maybe Int
    Nothing
    

  4. leftToMaybe :: Either l r -> Maybe l

    protolude Protolude.Either

    No documentation available.

  5. rightToMaybe :: Either l r -> Maybe r

    protolude Protolude.Either

    No documentation available.

  6. reifyTypeWithLocals_maybe :: DsMonad q => Name -> q (Maybe Type)

    th-desugar Language.Haskell.TH.Desugar

    Like reifyWithLocals_maybe but for types and kinds. Note that a return value of Nothing might mean that the name is not in scope, or it might mean that the full type of the name cannot be determined. (Use reifyWithLocals_maybe if you really need to tell the difference.)

  7. reifyWithLocals_maybe :: DsMonad q => Name -> q (Maybe Info)

    th-desugar Language.Haskell.TH.Desugar

    Like reify from Template Haskell, but looks also in any not-yet-typechecked declarations. To establish this list of not-yet-typechecked declarations, use withLocalDeclarations. Returns Nothing if reification fails. Note that no inferred type information is available from local declarations; bottoms may be used if necessary.

  8. tupleNameDegree_maybe :: Name -> Maybe Int

    th-desugar Language.Haskell.TH.Desugar

    Extract the degree of a tuple Name. In addition to recognizing tuple syntax (e.g., ''(,,)), this also recognizes the following:

    • ''Unit (for 0-tuples)
    • ''Solo/'MkSolo (for 1-tuples)
    • ''TupleN (for N-tuples)
    In recent versions of GHC, ''() is a synonym for ''Unit, ''(,) is a synonym for ''Tuple2, and so on. As a result, we must check for ''Unit and ''TupleN in tupleDegree_maybe to be thorough. (There is no special tuple syntax for ''Solo/'MkSolo, but we check them here as well for the sake of completeness.)

  9. unboxedSumNameDegree_maybe :: Name -> Maybe Int

    th-desugar Language.Haskell.TH.Desugar

    Extract the degree of an unboxed sum Name. In addition to recognizing unboxed sum syntax (e.g., ''()), this also recognizes ''SumN# (for unboxed N-ary sum type constructors). In recent versions of GHC, ''Sum2# is a synonym for ''(), ''Sum3# is a synonym for ''(), and so on. As a result, we must check for ''SumN# in unboxedSumNameDegree_maybe to be thorough.

  10. unboxedTupleNameDegree_maybe :: Name -> Maybe Int

    th-desugar Language.Haskell.TH.Desugar

    Extract the degree of an unboxed tuple Name. In addition to recognizing unboxed tuple syntax (e.g., ''()), this also recognizes the following:

    • ''Unit# (for unboxed 0-tuples)
    • ''Solo#/'Solo# (for unboxed 1-tuples)
    • ''TupleN# (for unboxed N-tuples)
    In recent versions of GHC, ''(##) is a synonym for ''Unit#, ''() is a synonym for ''Tuple2#, and so on. As a result, we must check for ''Unit#, and ''TupleN in unboxedTupleNameDegree_maybe to be thorough. (There is no special unboxed tuple type constructor for ''Solo#/'Solo#, but we check them here as well for the sake of completeness.)

Page 178 of many | Previous | Next