[Haskell-cafe] Re: [Haskell] View patterns in GHC: Request for
feedback
apfelmus
apfelmus at quantentunnel.de
Mon Jul 23 13:21:43 EDT 2007
Simon Marlow wrote:
> Dan Licata wrote:
>> Simon PJ and I are implementing view patterns, a way of pattern matching
>> against abstract datatypes, in GHC. Our design is described here:
>>
>> http://hackage.haskell.org/trac/ghc/wiki/ViewPatterns
>>
>> If you have any comments or suggestions about this design, we'd love to
>> hear them. You can respond to this list (and we can take it to
>> haskell-cafe if the thread gets long) or, if you prefer, directly to me.
>
> At the risk of being a spoil-sport, I have a somewhat negative take on
> view patterns. Not because I think they're particularly bad, but
> because I don't think they're significantly useful enough to warrant
> adding to the language, at least if we also have pattern guards.
>
> All of the examples on the wiki page can be written in the same number
> of lines, sometimes with fewer characters, using pattern guards or some
> other existing Haskell idiom (e.g. the bit parsing example is much more
> nicely expressed using a bit-parsing monad). I believe adding yet
> another idiom will be detrimental: too much choice is bad.
I agree that only few examples from the wiki page are that compelling.
Nevertheless, I like view patterns since they can be put to really good use
http://hackage.haskell.org/trac/ghc/wiki/ViewPatterns#UsesofViews
Views are especially useful for Data.Graph. Also, I favor views instead
of pattern guards.
However, I don't like the current proposal, mainly because it doesn't
have the "Transparent ordinary Patterns"-feature. Also, I consider
definitions like
foldr f z [] = z
foldr f z (x : foldr f z -> xs) = x `f` xs
abuse.
> Data.Set, Data.IntSet, Data.Map, Data.IntMap
> Data.Graph, Data.Sequence, Data.Bytestring, Data.Array,
> Data.HashTable, Data.Ratio(Rational)
>
> So I don't think there's an overwhelming amount of stuff that would
> change if we had view patterns. In GHC itself most of our data
> structures are already abstract too.
While the implementation of the abstract data structures themselves is
unlikely to change, views make it much easier to use them. I think it
would be a big win to have ByteStrings or Data.Sequence pattern matched
like ordinary lists and I think that Data.Graph will blossom with proper
view patterns.
Regards,
apfelmus
More information about the Haskell-Cafe
mailing list