<div dir="ltr">very cool!<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jan 22, 2022 at 9:33 PM David Feuer <<a href="mailto:david.feuer@gmail.com">david.feuer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I've put up a tiny little package[1], traverse-code, offering a<br>
generic way to "traverse" in Template Haskell's `Code m`.<br>
<br>
class TraverseCode t where<br>
  traverseCode :: Quote m => (a -> Code m b) -> t a -> Code m (t b)<br>
<br>
I wrote this primarily as a way to "lift" operations on polymorphic<br>
data structures into Template Haskell. For example, for Data.Sequence,<br>
you can write<br>
<br>
triple :: a -> a -> a -> Seq a<br>
triple a b c = $$(sequenceCode $ fromList [ [||a||], [||b||], [||c||] ])<br>
<br>
The `triple` function will not form its arguments into a list and then<br>
convert it to a sequence; rather, it will build the result sequence<br>
directly, using the underlying constructors.<br>
<br>
A generic default definition is available for all instances of<br>
Generics.Linear.Generic1. See linear-generics[2] for information about<br>
how to derive those. There's nothing particularly linear about<br>
traverse-code, but linear-generics has a more general Generic1 than<br>
GHC.Generics offers.<br>
<br>
[1] <a href="https://hackage.haskell.org/package/traverse-code" rel="noreferrer" target="_blank">https://hackage.haskell.org/package/traverse-code</a><br>
[2] <a href="https://hackage.haskell.org/package/linear-generics" rel="noreferrer" target="_blank">https://hackage.haskell.org/package/linear-generics</a><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<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>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>