Johan Tibell wrote:
> On 10/9/07, David Benbennick <[EMAIL PROTECTED]> wrote:
>> On 10/9/07, Johan Tibell <[EMAIL PROTECTED]> 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

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to