Practical usages for (common) type classes

Predominantly applicative-ish things:

  • Concurrent actions.

  • Composable folds over streaming data. (You can give Monad instances to streaming fold datatypes, but AFAIK they must keep the whole history of the stream to work, so it kind of defeats the purpose.)

  • Validations that keep all errors instead of just the first one.

  • Nested bracketing for resource allocation (this is also monadic, but it's mostly used in an applicative-ish way).

  • Actions carrying some kind of annotation that can be inspected before being running the action. (Also a use-case for arrows.)

  • Also Applicatives are very composable, be it with products, sums, Data.Functor.Compose or Data.Functor.Day.

Alternative-ish things:

  • Parsers

  • Concurrent actions that race each other.

  • Streams of data that can be interleaved.

  • Getting the first success out of a series of actions.

Comonad-ish things:

  • Non-empty somethings, can-always-provide-a-value somethings.

  • Values that carry some kind of environment.

  • Composable folds over streaming data (again).

/r/haskell Thread