[Haskell] View patterns in GHC: Request for feedback
Claus Reinke
claus.reinke at talk21.com
Tue Jul 24 06:54:31 EDT 2007
> though I'm extremely dubious about the utility of the "Maybe" patterns.
actually, they are the main thing that interests me about view patterns!-)
it connects them to the existing work on first-class patterns (where
combinators over Maybe patterns do the matching work, and view
patterns provide the syntax (a) for integrating Maybe patterns into
"dumb" patterns and (b) for binding the results of Maybe patterns to
pattern variables).
but then, i'd not so much use them as pretend views, but as abstract
deconstructors/observers in the unfoldr style. instead of constructing
real intermediate types, i'd have the implicit Maybe decide the match
and the returned subexpressions available in a tuple for further
matching or binding. eg, the first example would become:
type Typ
unit :: Typ -> Maybe ()
arrow :: Type -> Maybe (Typ,Typ)
size :: Typ -> Integer
size (unit -> ()) = 1
size (arrow -> (t1,t2)) = size t1 + size t2
closer to ordinary patterns, with the lowercase and the '->' hinting
that there is computation before matching (well, '=>', according to
the new proposal).
claus
More information about the Haskell
mailing list