* package:base

Multiplication of type-level naturals.
Sequence actions, discarding the value of the first argument.

Examples

If used in conjunction with the Applicative instance for Maybe, you can chain Maybe computations, with a possible "early return" in case of Nothing.
>>> Just 2 *> Just 3
Just 3
>>> Nothing *> Just 3
Nothing
Of course a more interesting use case would be to have effectful computations instead of just returning pure values.
>>> import Data.Char

>>> import GHC.Internal.Text.ParserCombinators.ReadP

>>> let p = string "my name is " *> munch1 isAlpha <* eof

>>> readP_to_S p "my name is Simon"
[("Simon","")]
Split the input between the two argument arrows and combine their output. Note that this is in general not a functor. The default definition may be overridden with a more efficient version if desired.
b ╭─────╮ b'
>───┼─ f ─┼───>
>───┼─ g ─┼───>
c ╰─────╯ c'
Low word of signed integer multiply.
Exponentiation.
Sequence actions, discarding the value of the second argument.
Sequential application. A few functors support an implementation of <*> that is more efficient than the default one.

Example

Used in combination with (<$>), (<*>) can be used to build a record.
>>> data MyState = MyState {arg1 :: Foo, arg2 :: Bar, arg3 :: Baz}
>>> produceFoo :: Applicative f => f Foo

>>> produceBar :: Applicative f => f Bar

>>> produceBaz :: Applicative f => f Baz
>>> mkState :: Applicative f => f MyState

>>> mkState = MyState <$> produceFoo <*> produceBar <*> produceBaz
A variant of <*> with the types of the arguments reversed. It differs from flip (<*>) in that the effects are resolved in the order the arguments are presented.

Examples

>>> (<**>) (print 1) (id <$ print 2)
1
2
>>> flip (<*>) (print 1) (id <$ print 2)
2
1
>>> ZipList [4, 5, 6] <**> ZipList [(+1), (*2), (/3)]
ZipList {getZipList = [5.0,10.0,2.0]}
Products: encode multiple arguments to constructors