<div dir="ltr"><div><div>First of all, in your use case are you sure that using Data.Vector is much less efficient than one of the specialized types?  It's possible that all the allocations are fused away entirely after all.<br>
<br></div>Secondly, the module Data.Vector.Generic allows you to write functions that will work on all types of vectors, including unboxed and Storable-based vectors.   Would it be possible to use this module to write the desired code?  You'd then need to include a type annotation only once at the top level.<br>
<br></div><div>Finally, I supposed you could get something like this by creating a class similar to Data.Vector.Generic but using closed type families.  I haven't worked out the details but I think it would work.  The vector would only be available for a pre-defined list of available types though.<br>
</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Jun 28, 2014 at 5:37 PM, Yuri Lensky <span dir="ltr"><<a href="mailto:ydl@ydl.cm" target="_blank">ydl@ydl.cm</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">I am having trouble consolidating a performance-based data representation decision I would like to make against the concept of a "functor". The question can be reduced to the following:</span><div style="font-family:arial,sans-serif;font-size:13px">

<br></div><div style="font-family:arial,sans-serif;font-size:13px">Conceptually I think that Data.Vector /should/ be a functor. More specifically, I see no CONCEPTUAL reason that it shouldn't be possible to define some "efficient" container-like object (for example for fast Matrix operations for unboxable numbers, but something that still works for a symbolic variable type) that chooses to represent its data as a Data.Vector.Unboxed if possible, but chooses some more generic structure (perhaps a strict list or a generic Data.Vector) if that is not the case. I haven't found such a functor, and can't seem to implement it on my own. The point is that in theory there is no true constraint on the type of the object being contained so it SHOULD be a Functor/Traversable/etc., the representation simply changes to something more efficient only if possible, and decays to a more generic type gracefully if necessary.</div>

<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Perhaps there is some type hackery that can be done with TypeFamilies? I.E. define some container type "data C a = (ListType a) a", but I haven't found a generic way to do this.</div>

<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Finally, I understand that "efficient" data structure can be problem-dependent, but I have no problem defining many different such "generic" types for different applications. The simplest example would be something like (invalid Haskell):</div>

<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">(Data.Vector.Unboxed.Vector v a) => data instance (ListType a) = v</div><div style="font-family:arial,sans-serif;font-size:13px">

(Data.Vector.Generic.Vector v a) => data instance (ListType a) = v</div><div style="font-family:arial,sans-serif;font-size:13px">data instance (ListType a) = ([])</div><div style="font-family:arial,sans-serif;font-size:13px">

<br></div><div style="font-family:arial,sans-serif;font-size:13px">Of course implementing fmap is a whole separate issue. The point is I do not think this is the right way/possible, but am wondering what the "true" solution is.</div>

<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Thanks.</div></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>