[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-cafe
Subject:    Re: [Haskell-cafe] [ANN]: traverse-code
From:       Carter Schonwald <carter.schonwald () gmail ! com>
Date:       2022-01-28 16:45:54
Message-ID: CAHYVw0zqNEbO694m79NeAzq-Njzuw2U5E6eNx7nGKM-ZaZXU6w () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


very cool!

On Sat, Jan 22, 2022 at 9:33 PM David Feuer <david.feuer@gmail.com> wrote:

> I've put up a tiny little package[1], traverse-code, offering a
> generic way to "traverse" in Template Haskell's `Code m`.
>
> class TraverseCode t where
>   traverseCode :: Quote m => (a -> Code m b) -> t a -> Code m (t b)
>
> I wrote this primarily as a way to "lift" operations on polymorphic
> data structures into Template Haskell. For example, for Data.Sequence,
> you can write
>
> triple :: a -> a -> a -> Seq a
> triple a b c = $$(sequenceCode $ fromList [ [||a||], [||b||], [||c||] ])
>
> The `triple` function will not form its arguments into a list and then
> convert it to a sequence; rather, it will build the result sequence
> directly, using the underlying constructors.
>
> A generic default definition is available for all instances of
> Generics.Linear.Generic1. See linear-generics[2] for information about
> how to derive those. There's nothing particularly linear about
> traverse-code, but linear-generics has a more general Generic1 than
> GHC.Generics offers.
>
> [1] https://hackage.haskell.org/package/traverse-code
> [2] https://hackage.haskell.org/package/linear-generics
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.

[Attachment #5 (text/html)]

<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 &lt;<a \
href="mailto:david.feuer@gmail.com">david.feuer@gmail.com</a>&gt; \
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&#39;ve put up a tiny \
little package[1], traverse-code, offering a<br> generic way to &quot;traverse&quot; \
in Template Haskell&#39;s `Code m`.<br> <br>
class TraverseCode t where<br>
   traverseCode :: Quote m =&gt; (a -&gt; Code m b) -&gt; t a -&gt; Code m (t b)<br>
<br>
I wrote this primarily as a way to &quot;lift&quot; operations on polymorphic<br>
data structures into Template Haskell. For example, for Data.Sequence,<br>
you can write<br>
<br>
triple :: a -&gt; a -&gt; a -&gt; 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&#39;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>


[Attachment #6 (text/plain)]

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic