While discussing whether `decoded` in `pipes-binary` should be an `Iso'` a `Getter'` or a `Lens'` [1], I started thinking what would be the advantages of each one from the parsing point of view.

The obvious advantage of the `Iso'` would be that it's automatically reversible using `from`[2], so you get `encoded` for free. But it turns out it's not truly reversible when facing errors, `lens-family` doesn't include the `from` function and it's in the end not that obvious to use for end users.

Using `Lens'`es for `decoded` and `encoded` raises the question that if we are considering the lenses irreversible, why not just use `Getter'`s? They wouldn't violate the lens laws and could be composed correctly with other lenses, folds, traversals..., when applicable. After all, if we have `Getter`s that transform `Producer`s as we need, what's the use of the *setter* part of a `Producer` lens?

Well, it turns out that `zoom` can't use `Getter`s [3], but I fail to understand how it uses the *setter* part, changing what the *setter* does, doesn't seem to affect `zoom`. There is also `magnify` which works like `zoom` with `Getter`s but it can't operate on the state monad [4].

So I was thinking why not include a version of `zoom` in `pipes-parse` that works with `Getter`s, using `mapStateT` for example [5], and base all pipes parsing on `Getter`s by default? What would be the disadvantages of this approach?

[1] https://github.com/k0001/pipes-binary/issues/12
[2] http://hackage.haskell.org/package/lens-4.0.1/docs/Control-Lens-Iso.html#v:from [3] http://hackage.haskell.org/package/lens-4.0.1/docs/Control-Lens-Zoom.html#v:zoom [4] http://hackage.haskell.org/package/lens-4.0.1/docs/Control-Lens-Zoom.html#v:magnify [5] http://hackage.haskell.org/package/transformers-0.3.0.0/docs/Control-Monad-Trans-State-Strict.html#v:mapStateT

-- Danny Navarro

--
You received this message because you are subscribed to the Google Groups "Haskell 
Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].

Reply via email to