+1 ! <div><br><br><div class="gmail_quote">On Fri, Mar 2, 2012 at 7:40 PM, Johan Tibell <span dir="ltr">&lt;<a href="mailto:johan.tibell@gmail.com">johan.tibell@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hi all,<div><br></div><div>These ideas are still in very early stages. I present them here in hope of starting a discussion. (We discussed this quite a bit at last year&#39;s ICFP, I hope this slightly different take on the problem might lead to new ideas.)</div>



<div><br></div><div>I think the next big step in Haskell performance is going to come from using better data representation in common types such as list, sets, and maps. Today these polymorphic data structures use both more memory and have more indirections than necessary, due to boxing of values. This boxing is due to the values being stored in fields of polymorphic type.</div>



<div><br></div><div>First idea: instead of rejecting unpack pragmas on polymorphic fields, have them require a class constraint on the field types. Example:</div><div><br></div><div>    data UnboxPair a b = (Unbox a, Unbox b) =&gt; UP {-# UNPACK #-} !a {-# UNPACK #-} !b</div>



<div><br></div><div>The Unbox type class would be similar in spirit to the class with the same name in the vector package, but be implemented internally by GHC. To a first approximation instances would only exist for fields that unpack to non-pointer types (e.g. Int.)</div>



<div><br></div><div>Second idea: Introduce a new pragma, that has similar effect on representations as DPH&#39;s [::] vector type. This new pragma does deep unpacking, allowing for more types to be instances of the Unbox type e.g. pairs. Example:</div>



<div><br></div><div>    data T = C {-# UNWRAP #-} (a, b)</div><div><br></div><div>If you squint a bit this pragma does the same as [: (a, b) :], except no vectors are involved. The final representation would be the unpacked representation of a and b, concatenated together (e.g. (Int, Int) would result in the field above being 128-bit wide on a 64-bit machine.</div>



<div><br></div><div>The meta-idea tying these two ideas together is to allow for some abstraction over representation transforming pragmas, such as UNPACK.</div><div><br></div><div>P.S. Before someone suggest using type families. Please read my email titled &quot;Avoiding O(n^2) instances when using associated data types to unpack values into constructors.&quot;</div>



<div><br></div><div>Cheers,</div><div>  Johan</div><div><br></div>
<br>_______________________________________________<br>
Glasgow-haskell-users mailing list<br>
<a href="mailto:Glasgow-haskell-users@haskell.org">Glasgow-haskell-users@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/glasgow-haskell-users" target="_blank">http://www.haskell.org/mailman/listinfo/glasgow-haskell-users</a><br>
<br></blockquote></div><br></div>