-
Notifications
You must be signed in to change notification settings - Fork 40
Description
Laziness can be useful with algebraic types. I recently implemented an experimental approach to laziness in my partial.lenses library. The idea is briefly discussed in issue 56.
The experimental approach used in partial.lenses is based on having an optional delay operation.
Concretely, in the case of Monoids, the optional delay has a signature like:
delay :: Monoid a => (() -> a) -> aAnd in the case of Applicatives, the delay has a signature like:
delay :: Applicative c => (() -> c a) -> c aIn some cases, it is possible to derive the delay operation from other operations. In the case of Monads:
const deriveDelayForMonad = M => u2xM =>
M.chain(_ => u2xM(), M.of(undefined))The support for laziness in partial.lenses is considered experimental partly due to not having the concept in the Static Land Specification. Perhaps Static Land could be enhanced with support for laziness?
Addition: The F# Computation Expression Zoo paper contains some relevant discussion on considerations for impure effects and delayed computations in a strict language in conjunction with algebraic types (mostly Monads).