<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Feb 7, 2016 at 2:25 AM, Tyson Whitehead <span dir="ltr"><<a href="mailto:twhitehead@gmail.com" target="_blank">twhitehead@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Quick question for the experts out there.<br>
<br>
I need to process some records. The records come in in an unordered stream of record fields. From each stream of fields I want to produce a Record entry containing the fields I need to do my calculation.<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
data Record = { field1 :: Type1, field2 :: Type2, ... }<br>
</blockquote>
<br>
I was thinking this setup might work nice with something like<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
data RecordF d = RecordF { field1 :: f Type1, field2 :: f Type2, ... }<br>
</blockquote>
<br>
as I could then have (1) a monoid version I could accumulate use as an accumulator over the stream<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
type RecordM = RecordF []<br>
</blockquote>
<br>
and (2) a final version.<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
type Record = RecordF Identity<br>
</blockquote>
<br>
This final version seems like it should easily come from the later by pulling the [] (or anything else that has the Apply/Applicative structure) to the outside and then taking the head of the resulting list.<br>
<br>
While I could write the boilerplate to do this, it seems like something I should be able to do more elegantly. The best I have come up with so far is to use the lens package to give me an isomorphism to a tuple. Then I need a uncurried zip for arbitrarily large tuples. Follow this by an isomorphism back.<br>
<br>
RecordF (f Type1) (f Type2) ... -> (f Type1, f Type2, ....)<br>
-> f (Type1, Type2, ...) -> f (Record Type1 Type2 ...)<br>
<br>
I can't seem to find any uncurried zip implementations for arbitrarily large tuples (or any other way to do this without writing the boilerplate). Am I missing something? Is there a better way to do this?<br>
<br>
Thanks! -Tyson<br>
<br>
PS: It seems the Data.Vinyl package has something along these lines with the rtraverse function<br>
<br>
<a href="https://hackage.haskell.org/package/vinyl-0.5.1/docs/Data-Vinyl-Core.html" rel="noreferrer" target="_blank">https://hackage.haskell.org/package/vinyl-0.5.1/docs/Data-Vinyl-Core.html</a><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br></blockquote><div><br></div><div></div><div><a href="https://gist.github.com/aavogt/f7d875abaf504dc3bf12" target="_blank">https://gist.github.com/aavogt/f7d875abaf504dc3bf12</a> shows how you can do it with extensible, HList, and vinyl.<br><br>Or if you want to stick with your current way of defining records, I think <a href="https://wiki.haskell.org/Template_Haskell#.27generic.27_zipWith">https://wiki.haskell.org/Template_Haskell#.27generic.27_zipWith</a> could work too.<br><br></div><div>Regards,<br></div><div>Adam<br></div></div><br></div></div>