[Haskell-cafe] Manual constructor specialization

Thomas Schilling nominolo at googlemail.com
Tue Oct 9 13:09:25 EDT 2007


On Tue, 2007-10-09 at 17:40 +0200, Johan Tibell wrote:
> On 10/9/07, David Benbennick <dbenbenn at gmail.com> wrote:
> > On 10/9/07, Johan Tibell <johan.tibell at gmail.com> wrote:
> > > data Rope = Empty
> > >           | Leaf
> > >           | Node !Rope !Rope
> >
> > > The point is that Empty
> > > can only appear at the top by construction
> >
> > How about indicating this in your data type?  I.e.,
> >
> > data Rope = Empty | NonEmptyRope
> > data NonEmptyRope = Leaf | Node !NonEmptyRope !NonEmptyRope
> >
> 
> That would be an idea. What are the performance effects of this? I'm
> trying to not have too many layers of indirection (I will spend quite
> some time reading -ddumpsimpl to optimize this library so anything
> that makes that simpler is a Good Thing.)

Another approach would be to define your invariant as a QuickCheck
property.  If you run your test suite often enough you will still find
errors quickly.

W.r.t. performance, note that allocating data on the C-stack might be
slow, so make sure you also measure this.

/ Thomas



More information about the Haskell-Cafe mailing list