archives

Catch me if you can: Towards type-safe, hierarchical, lightweight, polymorphic and efficient error management in OCaml

Catch me if you can: Towards type-safe, hierarchical, lightweight, polymorphic and efficient error management in OCaml, by David Teller, Arnaud Spiwack, Till Varoquaux:

This is the year 2008 and ML-style exceptions are everywhere. Most modern languages, whether academic or industrial, feature some variant of this mechanism. Languages such as Java even have a degree of out-of-the-box static coverage-checking for such exceptions, which is currently not available for ML languages, at least not without resorting to external tools.

In this document, we demonstrate a design principle and a tiny library for managing errors in a functional manner, with static coverage-checking, automatically-inferred, structurally typed and hierarchical exceptional cases, all of this for what we believe is a reasonable run-time cost. Our work is based on OCaml and features simple uses of higher-order programming, low-level exceptions, phantom types, polymorphic variants and compile-time code
rewriting.

Exhaustively checked, user-friendly exception handling was a bit of an open problem for awhile. As the paper details, languages supported either cumbersome, exhaustively checked polymorphic exceptions, as in Haskell, or we had unchecked easily extensible monomorphic exceptions, as in ML, or we had checked, extensible exceptions using a universal type as in Java.

Supporting exhaustively checked, easily extensible polymorphic exceptions seemed quite a challenge, which this paper solves using monadic error handling and nested polymorphic variants. The paper also gives a good overview of current techniques of exception checking in OCaml, ie. ocamlexc.

The performance of such exceptions is understandably lower than native exceptions, given all the thunking and indirection that monads entail. The authors attempt various implementations and test their performance against native exceptions. Ultimately, monadic error management seems acceptable for actual error handling, but not for control flow as native exceptions are sometimes used in OCaml.

One interesting extension is to consider how efficient the implementations would be given more sophisticated control flow operators, such as continuations, coroutines, or delimited continuations, or whether native exceptions can be salvaged using a type and effects system in place of monads.

In search for a programming language to replace spreadsheets.

Hello,

I'm in the search for a good programming language to replace much of what I use spreadsheets for today:
It should be constructed to easily define constants / sets of data, and calculating new data from other data, using user-defined formulas.

The advantage of a spreadsheet is that it's extremely easy and fast to work with. But a spreadsheet can soon become complex with:
- lots of long, hard-to-read formulas
- the same formula definitions duplicated all over the document
- data and formulas mixed up all over.

I would like a language that can be used like this:

You define a data field to be a function of multiple arguments like:

Amount Income(Company, Month, Year)

You can then derive other fields like:

Amount Income(Month, Year) = sum(Income(Company, Month, Year))
Amount Income(Year) = sum(Income(Month, Year))

You can also define a lot of data:

Amount Income(Company, Month, Year) = [
  ("Microsoft", "01", "2008") => 1234,
  ("Microsoft", "02", "2008") => 15664,
  ("Sun", "01", "2008") => 1564,
  ("Sun", "02", "2008") => 1652
]

You can now ask for

Income("2008")

and get the appropriate amount: (= sum [for all months] [for all companies] Income(Company, Month, "2008"))

I know many imperative languages, but I've only experimented very little with other programming paradigms. I'm thinking of learning a declarative language like Prolog for this .. but are there better alternatives? I like the idea of Haskell being strongly typed, but I don't know if it will be good for this.

The idea is to be able to model very complex systems, while keeping the calculations concise. Another advantage would be that you are able to reuse formulas. Ideally there should be a nice IDE with the possibility of getting a graphical/tabular view of the calculated data.

Have any of you thought of something like this, or even made or heard of something like this?
I would very much like to know your views on this, and if you know any good languages for this problem domain..