ANN: data-type-0.0.1, function-combine-0.0.1 and flexiwrap-0.0.1

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

ANN: data-type-0.0.1, function-combine-0.0.1 and flexiwrap-0.0.1

Iain Alexander
Package data-type contains a number of fundamental types and classes useful
for type-level programming, such as type-level booleans, natural numbers,
and lists.  All of them could no doubt be found elsewhere, including the
HList package[1,2], but this package aims to make them more accessible.
It is a prerequisite for the other two packages.

Package function-combine is the outcome of an exercise in type-level
programming (e.g. [3, 4]).  It illustrates implementations of

* A popular generalisation of function composition
-- compose zero = (.)
-- compose zero f g x = f (g x)
-- compose one f g x y = f (g x y)
... etc.

* A generalisation of flip
-- <rot n f> passes its first argument as the (n + 1)th argument
-- to <f>, rotating the intervening arguments along
-- e.g. <rot one> = flip

It is published primarily for reference purposes, as [yet] an[other] example
of the techniques involved.  If somebody happens to find it useful in its
own right, so much the better.

Package flexiwrap is a more substantial use of these techniques,
together with phantom types [6], to provide
a system of flexible wrappers, intended to facilitate the definition of
types which have specified typeclass instances, which is particularly useful
with composed types (see e.g. [5]).  Automatic instance derivation techniques
generally assume that there is only one appropriate candidate, which is
frequently not the case for composed types, whereas flexible wrappers
allow you to specify the required instance by name.  In particular,
an illustrative implementation of the Mark Jones / Luc Duponcheel scheme
for monad composition[7] is provided.

As a taster,

type StrictT = FWCTC
    (FWFlipDefaults :*:
        FWCompMonadPlusL :*: FWCompDefaults :*: FWCompS :*: TNil
    (FlipT O) Strict

defines a (e.g. monad, but in general constructor) transformer StrictT.
FWCTC is a flexible wrapper.  Its first parameter is an HList-like type-level
list of instance specifications.  O is the type composition operator,
and FlipT flips its arguments.  Strict is a user-defined constructor type.
FWCompMonadPlusL specifies a particular MonadPlus instance, and FWCompS
specifies the Jones/Duponcheel SComp construction [7].  The other two items
in the list (apart from the TNil terminator) specify default implementations
of other instances.

All three packages should be considered experimental.  The flexiwrap package
in particular is provided as a proof of concept - only enough typeclass
instances are provided to illustrate the idea, and many other details
are likely to change.  They will work with a wide range of versions of GHC,
but probably not other compilers.

[6] I don't know any good reference for the current usage of the term
    phantom types - I may yet write one.

Haskell mailing list
[hidden email]