[Haskell-cafe] A practical Haskell puzzle
wren ng thornton
wren at freegeek.org
Mon Feb 28 12:41:53 CET 2011
On 2/28/11 2:43 AM, Yitzchak Gale wrote:
> You have written a large software system in Haskell. Wishing to
> play to Haskell's strength, you have structured your system
> as a series of composable layers. So you have data types
>
> Layer1, Layer2, ...
>
> and functions
>
> layer2 :: Layer1 -> Layer2
> layer3 :: Layer2 -> Layer3
> ...
>
> etc.
Assuming you actually name them Layer1, Layer2, etc, or use any other
regular naming scheme, you can break apart the names and use typeclasses
to help out:
type family Layer :: * -> *
data Z
data S n
class Layerable n where
layer :: Layer n -> Layer (S n)
Then it's just a matter of getting the right number of them, a la
lifting through monad transformer stacks. Of course, from here it's not
that hard to add in some type hackery to do the lifting for you, a la
"Data types a la Carte"[1]. It's not the cleanest thing ---there's a
good deal of boilerplate up front--- but once it's set up, it should
Just Work(tm).
[1] http://www.cs.nott.ac.uk/~wss/Publications/DataTypesALaCarte.pdf
--
Live well,
~wren
More information about the Haskell-Cafe
mailing list