[Haskell-cafe] Re: Manual constructor specialization
ChrisK
haskell at list.mightyreason.com
Tue Oct 9 13:23:53 EDT 2007
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.)
What you might want as a wrapper is a strict version of a maybe type:
> data Rope = NoRope | JustRope {-# UNPACK #-} !ARope
> data ARope = Leaf {- rest of data here -}
> | Node {-# UNPACK #-} !NonEmptyRope {-# UNPACK #-} !NonEmptyRope
With the "constructor tagging" in the latest GHC the runtime indirection costs
for such 2-constructor types should be quite low.
--
Chris Kuklewicz
More information about the Haskell-Cafe
mailing list