Showing 1–2 of 2 results for author: Malakhovski, J
-
Programming with Applicative-like expressions
Authors:
Jan Malakhovski,
Sergei Soloviev
Abstract:
The fact that Applicative type class allows one to express simple parsers in a variable-less combinatorial style is well appreciated among Haskell programmers for its conceptual simplicity, ease of use, and usefulness for semi-automated code generation (metaprogramming).
We notice that such Applicative computations can be interpreted as providing a mechanism to construct a data type with "ports"…
▽ More
The fact that Applicative type class allows one to express simple parsers in a variable-less combinatorial style is well appreciated among Haskell programmers for its conceptual simplicity, ease of use, and usefulness for semi-automated code generation (metaprogramming).
We notice that such Applicative computations can be interpreted as providing a mechanism to construct a data type with "ports" "pluggable" by subcomputations. We observe that it is this property that makes them so much more convenient in practice than the usual way of building the same computations using conventional composition. We distill this observation into a more general algebraic structure of (and/or technique for expressing) "Applicative-like" computations and demonstrate several other instances of this structure.
Our interest in all of this comes from the fact that the aforementioned instances allow us to express arbitrary transformations between simple data types of a single constructor (similarly to how Applicative parsing allows to transform from streams of Chars to such data types) using a style that closely follows conventional Applicative computations, thus greatly simplifying (if not completely automating away) a lot of boiler-plate code present in many functional programs.
△ Less
Submitted 26 May, 2019;
originally announced May 2019.
-
Exceptionally Monadic Error Handling
Authors:
Jan Malakhovski
Abstract:
We notice that the type of catch :: c a -> (e -> c a) -> c a operator is a special case of monadic bind operator (>>=) :: m a -> (a -> m b) -> m b, the semantics (surprisingly) matches, and this observation has many interesting consequences.
For instance, the reader is probably aware that the monadic essence of the (>>=) operator of the error monad $λA.E \lor A$ is to behave like identity monad…
▽ More
We notice that the type of catch :: c a -> (e -> c a) -> c a operator is a special case of monadic bind operator (>>=) :: m a -> (a -> m b) -> m b, the semantics (surprisingly) matches, and this observation has many interesting consequences.
For instance, the reader is probably aware that the monadic essence of the (>>=) operator of the error monad $λA.E \lor A$ is to behave like identity monad for "normal" values and to stop on "errors". The unappreciated fact is that handling of said "errors" with a catch operator of the "flipped" "conjoined" error monad $λE.E \lor A$ is, too, a monadic computation that treats still unhandled "errors" as "normal" values and stops when an "error" is finally handled.
We show that for an appropriately indexed type of computations such a "conjoined" structure naturally follows from the conventional operational semantics of throw and catch operators. Consequently, we show that this structure uniformly generalizes all conventional monadic error handling mechanisms we are aware of. We also demonstrate several more interesting instances of this structure of which at least bi-indexed monadic parser combinators and conventional exceptions implemented via continuations have immediate practical applications. Finally, we notice that these observations provide surprising perspectives on error handling in general and point to a largely unexplored trail in programming language design space.
△ Less
Submitted 30 January, 2019; v1 submitted 31 October, 2018;
originally announced October 2018.