[Haskell-cafe] ANN: convertible (first release)

John Goerzen jgoerzen at complete.org
Mon Jan 26 22:52:54 EST 2009

Hi folks,

I have uploaded a new package to Haskell: convertible.  At its heart,
it's a very simple typeclass that's designed to enable a reasonable
default conversion between two different types without having to
remember a bunch of functions.

The return type from this conversion is "Either ConvertError a", and
conversions are expected to do sanity checking (such as bounds
checking when converting to types like Int), so as to produce neither
garbage nor exceptions as part of the conversion process.

The package also includes instances of the Convertible typeclass for
working with numeric types as well as dates and times.  Notably, it
has code to convert between System.Time types and their Data.Time
siblings, and vice versa, a capability I found annoyingly lacking in
the standard library.

There is also a simple wrapper function called convert, that
transforms a Left result into a call to error, and returns a Right

For HDBC v2.0, the SqlValue/SqlType system has been completely
rewritten in terms of Convertible, though I expect backwards
compatibility will not be broken by this change (existing code will
compile and run fine).  I hope to release v2.0 of the HDBC API and
backends in a few days.

Convertible is not for everyone; if you care whether you use truncate
or round to convert a Double to an Integer, this isn't for you.  Note,
though, that you can import the library without its default instances,
so you can define your own if you prefer.

API docs and downloads at:


-- John

More information about the Haskell-Cafe mailing list