
Sometimes I'd like to use a smart constructor but have pattern matching as well. There has been talk elsewhere of allowing export of data constructors for /matching/ but not for /construction/: --------module One--------- data Picky a = Nil | One a picky x = if some_complex_thing x then One x else Nil --------module Two--------- f x = g $ picky x g Nil y = y g (One x) y = x h Nil = One True ----------------- I'd like for the function g to be fine and the function h to get a complaint like "error: no constructor 'One'" or, even better, "error: 'One' only works in pattern matching" Jim

Jim - it's worth looking at the proposal for views, proposed by Warren Burton et al, accessible from http://haskell.galois.com/cgi-bin/haskell-prime/trac.cgi/wiki/Views regards Simon T On Thu, 9 Feb 2006, Jim Apple wrote:
Sometimes I'd like to use a smart constructor but have pattern matching as well. There has been talk elsewhere of allowing export of data constructors for /matching/ but not for /construction/:
--------module One--------- data Picky a = Nil | One a picky x = if some_complex_thing x then One x else Nil --------module Two--------- f x = g $ picky x
g Nil y = y g (One x) y = x
h Nil = One True -----------------
I'd like for the function g to be fine and the function h to get a complaint like "error: no constructor 'One'" or, even better, "error: 'One' only works in pattern matching"
Jim _______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://haskell.org/mailman/listinfo/haskell-prime

On Thu, 9 Feb 2006, S.J.Thompson wrote:
Jim - it's worth looking at the proposal for views, proposed by Warren Burton et al, accessible from
http://haskell.galois.com/cgi-bin/haskell-prime/trac.cgi/wiki/Views
Myself I'm of the view transformational patterns (as described in http://citeseer.ist.psu.edu/299277.html) are more interesting - I can't help wondering why they were never implemented? -- flippa@flippac.org "My religion says so" explains your beliefs. But it doesn't explain why I should hold them as well, let alone be restricted by them.

Philippa Cowderoy wrote:
Myself I'm of the view transformational patterns (as described in http://citeseer.ist.psu.edu/299277.html) are more interesting - I can't help wondering why they were never implemented?
Maybe because of tricky semantics. I'm not quite sure what case x of (y,z)!f -> ... where f _ = (z,3) should desugar to. -- Ben

Views were implemented in hbc many, many years ago.
-- Lennart
Quoting Philippa Cowderoy
On Thu, 9 Feb 2006, S.J.Thompson wrote:
Jim - it's worth looking at the proposal for views, proposed by Warren Burton et al, accessible from
http://haskell.galois.com/cgi-bin/haskell-prime/trac.cgi/wiki/Views
Myself I'm of the view transformational patterns (as described in http://citeseer.ist.psu.edu/299277.html) are more interesting - I can't help wondering why they were never implemented?
-- flippa@flippac.org
"My religion says so" explains your beliefs. But it doesn't explain why I should hold them as well, let alone be restricted by them. _______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://haskell.org/mailman/listinfo/haskell-prime

Philippa Cowderoy
Myself I'm of the view transformational patterns (as described in http://citeseer.ist.psu.edu/299277.html) are more interesting - I can't help wondering why they were never implemented?
Ah, so I wasn't first in implementing them in my language :-) It includes the following kinds of patterns (x is the value to be matched): when f args... | matches if f x args... is true | where f args... p | matches if p matches f x args... | p1 & p2 | matches if both p1 and p2 match | (p2 may use variables bound by p1) | define {defs} | matches anything, executes definitions, | binds variables they introduce | if cond | matches anything if cond is true | match e p | matches anything if p matches e This seems complex, OTOH it doesn't have guards. Haskell wouldn't need those "args..." because it curries. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/

On 2/9/06, S.J.Thompson
Jim - it's worth looking at the proposal for views, proposed by Warren Burton et al, accessible from
http://haskell.galois.com/cgi-bin/haskell-prime/trac.cgi/wiki/Views
Views have been getting a "no", and it seems like this is because of pattern guards. I see this exporting trick as much more lightweight than views, as it doesn't change any syntax except the export list, exacts no run-time cost, and doesn't (I think) require type system changes. And pattern guards don't solve the problem. That doesn't mean that I'm smart enough to implement my suggestion so we can all have a look at how it might work out. :-) Jim

On Thu, Feb 09, 2006 at 01:33:59AM -0500, Jim Apple wrote:
Sometimes I'd like to use a smart constructor but have pattern matching as well. There has been talk elsewhere of allowing export of data constructors for /matching/ but not for /construction/:
Yes. this is a feature I have wanted too. I made a proposal and put it on the wiki. http://haskell.galois.com/cgi-bin/haskell-prime/trac.cgi/wiki/ReadonlyConstr... John -- John Meacham - ⑆repetae.net⑆john⑈
participants (7)
-
Ben Rudiak-Gould
-
Jim Apple
-
John Meacham
-
lennart@augustsson.net
-
Marcin 'Qrczak' Kowalczyk
-
Philippa Cowderoy
-
S.J.Thompson