Hoogle Search

Within LTS Haskell 24.28 (ghc-9.10.3)

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

  1. mapSubexprs :: (Expr -> Maybe Expr) -> Expr -> Expr

    express Data.Express.Map

    O(n*m). Substitute subexpressions of an expression using the given function. Outer expressions have more precedence than inner expressions. (cf. //) With:

    > let xx = var "x" (undefined :: Int)
    > let yy = var "y" (undefined :: Int)
    > let zz = var "z" (undefined :: Int)
    > let plus = value "+" ((+) :: Int->Int->Int)
    > let times = value "*" ((*) :: Int->Int->Int)
    > let xx -+- yy = plus :$ xx :$ yy
    > let xx -*- yy = times :$ xx :$ yy
    
    > let pluswap (o :$ xx :$ yy) | o == plus = Just $ o :$ yy :$ xx
    |     pluswap _                           = Nothing
    
    Then:
    > mapSubexprs pluswap $ (xx -*- yy) -+- (yy -*- zz)
    y * z + x * y :: Int
    
    > mapSubexprs pluswap $ (xx -+- yy) -*- (yy -+- zz)
    (y + x) * (z + y) :: Int
    
    Substitutions do not stack, in other words a replaced expression or its subexpressions are not further replaced:
    > mapSubexprs pluswap $ (xx -+- yy) -+- (yy -+- zz)
    (y + z) + (x + y) :: Int
    
    Given that the argument function is O(m), this function is O(n*m).

  2. mapValues :: (Expr -> Expr) -> Expr -> Expr

    express Data.Express.Map

    O(n*m). Applies a function to all terminal values in an expression. (cf. //-) Given that:

    > let zero  = val (0 :: Int)
    > let one   = val (1 :: Int)
    > let two   = val (2 :: Int)
    > let three = val (3 :: Int)
    > let xx -+- yy = value "+" ((+) :: Int->Int->Int) :$ xx :$ yy
    > let intToZero e = if typ e == typ zero then zero else e
    
    Then:
    > one -+- (two -+- three)
    1 + (2 + 3) :: Int
    
    > mapValues intToZero $ one -+- (two -+- three)
    0 + (0 + 0) :: Integer
    
    Given that the argument function is O(m), this function is O(n*m).

  3. mapVars :: (Expr -> Expr) -> Expr -> Expr

    express Data.Express.Map

    O(n*m). Applies a function to all variables in an expression. Given that:

    > let primeify e = if isVar e
    |                  then case e of (Value n d) -> Value (n ++ "'") d
    |                  else e
    > let xx = var "x" (undefined :: Int)
    > let yy = var "y" (undefined :: Int)
    > let xx -+- yy = value "+" ((+) :: Int->Int->Int) :$ xx :$ yy
    
    Then:
    > xx -+- yy
    x + y :: Int
    
    > primeify xx
    x' :: Int
    
    > mapVars primeify $ xx -+- yy
    x' + y' :: Int
    
    > mapVars (primeify . primeify) $ xx -+- yy
    x'' + y'' :: Int
    
    Given that the argument function is O(m), this function is O(n*m).

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

    foundation Foundation

    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]
    

  5. mappend :: Monoid a => a -> a -> a

    foundation Foundation

    An associative operation NOTE: This method is redundant and has the default implementation mappend = (<>) since base-4.11.0.0. Should it be implemented manually, since mappend is a synonym for (<>), it is expected that the two functions are defined the same way. In a future GHC release mappend will be removed from Monoid.

  6. mapM :: (Mappable collection, Applicative m, Monad m) => (a -> m b) -> collection a -> m (collection b)

    foundation Foundation.Collection

    Map each element of the collection to an action, evaluate these actions from left to right, and collect the results. For a version that ignores the results see mapM_.

  7. mapM_ :: (Mappable col, Applicative m, Monad m) => (a -> m b) -> col a -> m ()

    foundation Foundation.Collection

    Evaluate each action in the collection from left to right, and ignore the results. For a version that doesn't ignore the results see sequenceA. sequenceA_ :: (Mappable col, Applicative f) => col (f a) -> f () sequenceA_ col = sequenceA col *> pure () Map each element of a collection to a monadic action, evaluate these actions from left to right, and ignore the results. For a version that doesn't ignore the results see mapM.

  8. maps :: Dims -> (Array a -> Array b) -> Array a -> Array b

    harpie Harpie.Array

    Maps a function along specified dimensions.

    >>> pretty $ maps [1] transpose a
    [[[0,12],
    [4,16],
    [8,20]],
    [[1,13],
    [5,17],
    [9,21]],
    [[2,14],
    [6,18],
    [10,22]],
    [[3,15],
    [7,19],
    [11,23]]]
    

  9. maps :: forall (ds :: [Nat]) (s :: [Nat]) (s' :: [Nat]) (si :: [Nat]) (si' :: [Nat]) (so :: [Nat]) a b . (KnownNats s, KnownNats s', KnownNats si, KnownNats si', KnownNats so, si ~ Eval (DeleteDims ds s), so ~ Eval (GetDims ds s), s' ~ Eval (InsertDims ds so si'), s ~ Eval (InsertDims ds so si)) => Dims ds -> (Array si a -> Array si' b) -> Array s a -> Array s' b

    harpie Harpie.Fixed

    Maps a function along specified dimensions.

    >>> pretty $ maps (Dims @'[1]) transpose a
    [[[0,12],
    [4,16],
    [8,20]],
    [[1,13],
    [5,17],
    [9,21]],
    [[2,14],
    [6,18],
    [10,22]],
    [[3,15],
    [7,19],
    [11,23]]]
    

  10. mapAccumWithKeyL :: TraversableWithKey t => (Key t -> a -> b -> (a, c)) -> a -> t b -> (a, t c)

    keys Data.Key

    The mapAccumWithKeyL function behaves like a combination of mapWithKey and foldlWithKey; it applies a function to each element of a structure, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new structure.

Page 194 of many | Previous | Next