<p>I don&#39;t have a proposal, but I&#39;d like to echo my support for thinking about this problem. It is very annoying to use my own types with unboxed vectors.</p>
<div class="gmail_quote">On May 30, 2012 12:28 AM, &quot;Ben Gamari&quot; &lt;<a href="mailto:bgamari.foss@gmail.com">bgamari.foss@gmail.com</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
One of the reasons I find Haskell so well suited to my work is its<br>
ability to easily work with large quantities of data. In particular, I<br>
find myself using Data.Vector.Unbox quite frequently.<br>
<br>
Another of my reasons for using Haskell is the type safety it<br>
provides. I find myself using newtypes very frequently to force myself<br>
to think about invariants that a more weakly typed language would allow<br>
me to simply ignore.<br>
<br>
Sadly, these two features don&#39;t interact particularly well. While the<br>
Data.Vector.Unbox documentation claims that &quot;Implementing unboxed<br>
vectors for new data types can be very easy&quot;, it then goes on to list an<br>
abridged version of the Complex instance---dozens of lines of<br>
code. While this code certainly isn&#39;t difficult to write, it is time<br>
consuming, error-prone, and, above else, utterly mind deadeningly dull<br>
(making it quite uncharacteristic for Haskell). So dull that I generally<br>
avoid newtypes at all cost in code that might need to use unboxed<br>
vectors. This boilerplate is largely due to Vector&#39;s use of type<br>
families as this precludes the use of (the otherwise quite cunning)<br>
GeneralizedNewtypeDeriving to automatically derive the necessary<br>
instances.<br>
<br>
What can be done to fix this unfortunate state of affairs? The obvious<br>
solution here seems to be Template Haskell, but this seems a bit of an<br>
unfortunate hack around what might be a deficiency in the type families<br>
mechanism (or at least this application of it). The newtype package<br>
provides a nice mechanism to pack and unpack newtypes, but providing<br>
blanket Unbox instances for Newtype instances seems like an awful idea<br>
(and, frankly, I&#39;m not sure how this would work with type<br>
families). Other than these two possibilities I am at a loss. Thoughts?<br>
I&#39;d appreciate any ideas folks could offer.<br>
<br>
Cheers,<br>
<br>
- Ben<br>
<br>
<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
</blockquote></div>