Ремонт принтеров, сканнеров, факсов и остальной офисной техники


назад Оглавление вперед




[24]

The example code shows the use of the filterM function within a do-block. It prints the subset of its arguments that specify directories and ignores non-directory arguments.

Example 6

This example is discussed in the section: Monad support in Haskell.

The example code shows the use of the liftM function within a do-block. It looks up a name in a list and uses a lifted String manipulation function to modify it within the Maybe monad.

Example 7

This example is discussed in the section: Monad support in Haskell.

The example code shows a higher-order application of liftM2. It folds lifted operations within the List monad to produce lists of all combinations of elements combined with the lifted operator.

Example 8

This example is discussed in the section: Monad support in Haskell.

The example code shows a higher-order application of ap. It folds ap through a list of Maybe (a->a) functions to process sequences of commands.

Example 9

This example is discussed in the section: Monad support in Haskell.

The example code shows the use of msum in the Maybe monad to select the first variable match in a stack of binding environments.

Example 10

This example is discussed in the section: Monad support in Haskell.

The example code shows the use of guard in the Maybe monad to select only the records from a list that satisfy a predicate (equivalent to filter).

ФП 02005-03 01

Лист 78

№ докум.

Копиоова Фоомат


Example 11

This example is discussed in the section: The Maybe monad.

The example code shows how to use the Maybe monad to build complex queries from

simpler queries that may fail to return a result. The specific example used is looking up mail

preferences for someone based on either their full name or a nickname.

Example 12

This example is discussed in the section: The Error monad.

The example code demonstrates the use of the Either type constructor as an Error monad with a custom error type. The example parses hexadecimal digits and uses the exception handling mechanism of the Error monad to provide informative error messages in the event of a parse failure.

Example 13

This example is discussed in the section: The List monad.

The example code uses the built-in list type constructor as a monad for non-deterministic computation. The example demonstrates parsing an ambiguous grammar consisting of integers, hex values, and words.

Example 14

This example is discussed in the section: The IO monad.

The example code implements a simple version of the standard Unix command "tr". The example demonstrates use of the IO monad including implicit fail calls due to pattern matching failures and the use of catcherror.

Example 15

This example is discussed in the section: The State monad.

The example code shows how the State monad can be used instead of explicitly passing state. The example uses the State monad to manage the random number generator state while building a compound data value requiring multiple calls to the random number generator.

ФП 02005-03 01

Лист 79

№ докум.

Копиоова Формат


Example 16

This example is discussed in the section: The Reader monad.

The example code shows how the Reader monad can be used to simplify computations involving a shared environment. The example uses the Reader monad to implement a simple template substitution system. The example code demonstrates the use of the Parsec monadic parser combinator library.

Example 17

This example is discussed in the section: The Writer monad.

The example code shows how the Writer monad can be used to implement logging. The example implements a very simple firewall simulator and uses the Writer monad to log the firewall activity.

Example 18

This example is discussed in the section: The Continuation monad.

The example code shows how the Continuation monads escape continuations work. The example computes a complex transformation of a number.

Example 19

This example is discussed in the section: Combining monads the hard way.

The example code shows how the Continuation monad can be nested within the IO monad given a suitable computational structure. The example is a slight modification of example 18.

Example 20

This example is discussed in the section: Combining monads the hard way.

The example code shows how the Continuation monad and IO monad can be used simultaneously, but without using monad transformers. The example builds on examples 18 and 19.

Example 21

This example is discussed in the section: Monad transformers.

ФП 02005-03 01

Лист 80

№ докум.

Копиоова Фоомат



[стр.Начало] [стр.1] [стр.2] [стр.3] [стр.4] [стр.5] [стр.6] [стр.7] [стр.8] [стр.9] [стр.10] [стр.11] [стр.12] [стр.13] [стр.14] [стр.15] [стр.16] [стр.17] [стр.18] [стр.19] [стр.20] [стр.21] [стр.22] [стр.23] [стр.24] [стр.25]