Re: [q-lang-users] Views and Virtual Constructors
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2007-06-27 22:07:53
|
Rob Hubbard wrote: > That is, is there a way for 'overlapping' views to be defined for use > by the new pattern matching feature on virtual constructors? No, not with the notion of views that Q currently implements. This is the same kind of "alternative views" feature also discussed in the "New stuff in cvs: multichar ops, views" thread. To implement this feature, a more powerful notion of views would be needed, which has something like the "value input feature", see http://hackage.haskell.org/trac/ghc/wiki/ViewPatterns for a discussion of various approaches. The notion of views proposed there for Haskell allows this, effectively, by specifying the particular 'view' routine to invoke when matching the pattern. Then you could write something like: foo (mylist_view1 -> mylist_cons H T) = ...; bar (mylist_view2 -> mylist_join X Y) = ...; But I don't really see the point in this, as you can already have as many ordinary access operations on an ADT which deliver as many different concrete representations of the data as you want, and match against these inside a 'where' clause: foo L:MyList = ... where mylist_cons H T = mylist_view1 L; bar L:MyList = ... where mylist_join X Y = mylist_view2 L; This isn't much clumsier and doesn't require any special kind of view implementation. For me, views, in the spirit of Wadler's original proposal, are just a convenience to make an ADT look like a concrete algebraic type with its own "canonical" representation in terms of a given set of constructors. In Q this virtual representation is then also used for pretty-printing, so that you have "what you see is what you (can) get" in terms of pattern-matching. This is convenient, simple and straightforward to use. I don't see right now what the more elaborate view notions buy you that you cannot achieve just as easily with some appropriate access operations and a 'where' clause. Someone please set me straight if I'm missing something important there. ;-) Cheers, Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |