Functor, Foldable and Traversable for Expr

Ben Gamari ben at well-typed.com
Mon Jun 18 15:38:38 UTC 2018


Sebastian Graf <sgraf1337 at gmail.com> writes:

> OK, so just deriving the instances doesn't yield the expected behavior,
> because the `Var` case explicitly mentions `Id`s instead of the type
> parameter `b`.
> Even if that would be changed, it's not easy to pin down over which parts
> of the syntax tree we should 'map'.
> Should we include binding sites of local variables? I'm inclined to say No,
> but only because I have my concrete use case in mind.
>
> It's probably best to have non-derived, non-typeclass functions
> `foldMapVars :: Monoid m => (Id -> m) -> Expr b -> m`, or a variant where
> the mapping function also gets supplied a value of `data NameSite = Lam |
> Let | VarRef` (for lack of a better name).
>
Agreed, I think there is enough subtlety here that it's best to be
explicit about which things in particular you want to traverse.

Cheers,

- Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20180618/b864776b/attachment.sig>


More information about the ghc-devs mailing list