[Haskell-cafe] [ANN]: traverse-code

Carter Schonwald carter.schonwald at gmail.com
Fri Jan 28 16:45:54 UTC 2022


very cool!

On Sat, Jan 22, 2022 at 9:33 PM David Feuer <david.feuer at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20220128/d0842e33/attachment.html>


More information about the Haskell-Cafe mailing list