[Haskell-cafe] Re: [Haskell] View patterns in GHC: Request for feedback

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Wed Jul 25 11:33:12 EDT 2007


Simon Marlow <simonmarhaskell at gmail.com> writes:

> Dan Licata wrote:
> 
> > Simon PJ and I are implementing view patterns, a way of
> > pattern matching against abstract datatypes, in GHC.
> 
> 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.

I wholeheartedly agree.

I'd rather see a slightly different question addressed: how
to permit the definition of overloaded functions using
pattern matching (and I mean pattern matching with exactly
the same syntax as anywhere else). In other words, if I write

> f [] = e
> f (a:b) g a b

I currently only get f :: [t] -> something, so if I later
discover that I need to change the input representation to
be more efficient than lists, I have to rewrite f. Wouldn't
it be so much nicer if I could simply add a declaration

> f:: Stream s => s t -> something

and get a function that works on anything in the Stream
class?

The core of the idea would be to allow classes to include
constructors (and associated destructors) so the definition
of Stream would include something for ":" and "[]" and their
inverses, though I've no real idea of the details; can
anyone come up with a plan?


* * *

It's essential to this idea that it doesn't involve any new
pattern matching syntax; the meaning of pattern matching for
overloaded functions should be just as transparent as for
non-overloaded ones.

-- 
Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk



More information about the Haskell-Cafe mailing list