Pattern guards

1997-05-13 Thread Simon L Peyton Jones
The discussion about pattern guards has raised two interesting and (I think) independent questions: - Nested guards - Maybes and monads Here are my thoughts on these things, typed 30,000 feet above Utah! Simon Nested guards ~~ Several people have pointed out

Re: Pattern guards

1997-05-14 Thread Greg Michaelson
Simon wrote: > For example, in this case we could write (rather less elegantly) > > g2 a | (x:xs) <- h a, (y:ys) <- h x = if y<0 then e1 >else if y>0 then e2 >else e3 > > To avoid this difficulty with functions li

Re: Pattern guards

1997-05-14 Thread Heribert Schuetz
Simon L Peyton Jones writes: > The discussion about pattern guards has raised two interesting and > (I think) independent questions: I think these questions are independent to some degree, but not entirely unrelated. I have written a few sentences on this in an earlier message, but perha

Re: Pattern guards

1997-05-14 Thread Simon L Peyton Jones
| > For example, in this case we could write (rather less elegantly) | > | > g2 a | (x:xs) <- h a, (y:ys) <- h x = if y<0 then e1 | >else if y>0 then e2 | >else e3 | > | > To avoid this difficulty with functions l

Re: Pattern guards

1997-05-15 Thread Simon L Peyton Jones
| > f c | (i,j) <- Just (toRect c) = ... | | I'm afraid this example suffers from the same problem as my "simplify" | example did: It does not perform a test and can thus be replaced by | | f c = ... | where (i,j) = toRect c True. I can think of two non-contrived ways in which this

Nested pattern guards.

1998-10-01 Thread Alex Ferguson
Hi all. Was there ever any sort of consensus about whether pattern guards ought to be "nestable", or not? And if not, was there some semantic objection to this, was the syntax just considered to Unspeakable to be spoken of, or is the feature just largely redundant? (I think you

Re: pattern guards + monads

1997-05-15 Thread Malcolm Wallace
I am having a little trouble following the two discussions on pattern guards and monads, due to some (probably minor) confusing pieces of syntax. Would anyone like to clarify these for me? It would help me to understand the underlying issues. Thanks. On pattern guards, Simon PJ writes

Re: pattern guards + monads

1997-05-15 Thread Philip Wadler
> Now, for monads, Phil Wadler writes a law: > > m >>= \x -> k x ++ h x = m >>= k ++ n >>= k > > in which 'h' appears on the lhs but not the rhs, and 'n' on the rhs but > not the lhs. ... perhaps the equation should read as follows? > m >>= \x -> k x ++ h x = m >>= k ++ m >>= h

Re: pattern guards + monads

1997-05-15 Thread Simon L Peyton Jones
| On pattern guards, Simon PJ writes: | > f (x:xs) | x<0 = e1 | > | x>0 = e2 | > | otherwise = e3 | | then | > g a | (x:xs) <- h a, x<0 = e1 | > | (x:xs) <- h a, x>0 = e1 | > | otherwise = e3 | | Am i right in thinking th

RE: Nested pattern guards.

1998-10-05 Thread Alex Ferguson
of off the top of my head are: taste and decency; and perhaps heavy reliance on the offside rule, which might be a bad thing if equation groups get infeasibly large. > The beauty of flat pattern guards is > that they have the same syntax as qualifiers in list comprehensions. Surely thi

RE: Nested pattern guards.

1998-10-05 Thread Simon Peyton-Jones
> Hi all. Was there ever any sort of consensus about whether pattern > guards ought to be "nestable", or not? > > And if not, was there some semantic objection to this, was the syntax > just considered to Unspeakable to be spoken of, or is the feature > just larg

[Haskell] No Pattern Guards

2005-03-28 Thread Yitzchak Gale
I posted a link to the following on the HaskellTwo wiki page. Please comment. I would like to suggest that PatternGuards NOT be included in HaskellTwo. While I enjoyed Simon Peyton Jones' well-written note on pattern guards [http://research.microsoft.com/Users/simonpj/Haskell/guards.html]

pattern guards and guarded patterns

1997-04-30 Thread Chris Dornan
know where I could get a copy of this proposal? > I would really welcome feedback on this proposal Here goes, ... Reaction to Pattern Guards == * I am sure that I have been nobbled by the lack of pattern guards regularly but have got used to clunking m

pattern guards and guarded patterns

1997-04-30 Thread Tommy Thorn
I can see the arguments for the pattern guard extension and the syntax seem reasonable. I also agree with Chris on the shortcomings of if-then-else. (I have disliked it in any language where I've seen it, and it "feels" un-Haskell-like to me.) On the other hand, the suggested case | ..

Re: Pattern guards vs. case

2001-03-01 Thread Malcolm Wallace
> runRandom last max num > | num > 1 = runRandom (fst new) max (num-1) > | otherwise = snd new > What's the difference between the pipe-syntax, and a case statement, > i.e. writing the function as >runRandom last max num = case num of > 1 -> runRandom > otherwise -> sn

Re: [Haskell] No Pattern Guards

2005-03-28 Thread John Meacham
list comprehensions being 'do' notation limited to the list monad and pattern guards being the 'do' notation limited to the identity monad. > Furthermore, the new syntax confuses the semantics of existing constructs. > > Referring to Simon's principal exa

Re: [Haskell] No Pattern Guards

2005-03-28 Thread Malcolm Wallace
John Meacham <[EMAIL PROTECTED]> writes: > Oddly enough, I was looking over the old Haskell discussions, and > pattern guards were supposed to make it into Haskell 98 according to the > decision. Any idea what happened? did someone just forget to write them > up or was there

Re: [Haskell] No Pattern Guards

2005-03-28 Thread Claus Reinke
> Now generalize it to more than two cases, or one where the second case > needs to pattern match too. The magic of pattern guards is not in a > single guarding expression, but in a function with many different cases > which use pattern guards. MonadPlus is your friend, especially if

Re: pattern guards and guarded patterns

1997-04-30 Thread Pablo E. Martinez Lopez
>I have longstanding dislike of Haskell's expression conditional: > The problem comes when several conditions are > present, provoking a rightward march. In this case I use > > if test1 then > part1 > else if test2 then >

Re: pattern guards and guarded patterns

1997-04-30 Thread Simon L Peyton Jones
Thanks for feedback about pattern guards. Here are some quick responses. 1. Several people have suggested something along the lines of being able to backtrack half way through a pattern guard. I considered this but (a) I couldn't see a nice syntax for it and (b) it's against

Re: pattern guards and guarded patterns

1997-04-30 Thread Philip Wadler
Tommy Thorn writes: > My only worry is that Haskell (if not already) is turning into the C++ > of functional languages, ie. feature upon feature. Haskell is already > quite a mouthfull to learn. This worries me too. Not least is the problem that <- is not a particularly natural syntax for this

Re: pattern guards and guarded patterns

1997-04-30 Thread Alex Ferguson
ds to existing Haskell if/boolean case functionality. But this doesn't, and can't be made to, do any sort of pattern-binding, so it's not possible to express pattern guards like this. (Or reduce them to such in the same style of translation as Chris gave.) Brian Boutel comments on Simo

Re: pattern guards and guarded patterns

1997-05-01 Thread Brian Boutel
> 3. I think it's quite important to use "<-" rather than "=". > a) it means that the syntax is precisely that of list comprehensions > b) there's an "=" in the definition already, as Andy points out: > simplify (Plus e e') | let (Val 0) = s = s' >

Re: pattern guards and guarded patterns

1997-05-02 Thread Guillermo Calderon
I think Herbert's monadic version of "clunky" is really satisfactory : >clunky env var1 var2 = fromJust (do val1 <- lookup var1 env > val2 <- lookup var2 env > return (var1 + var2) > ++ >

Re: pattern guards and guarded patterns

1997-05-01 Thread Pablo E. Martinez Lopez
Errata: in my previous mail, the text "a la Hoare" should be replaced by "a la Dijkstra". Fidel.

[Haskell] Pattern guards and algebraic datatypes

2004-06-18 Thread Graham Klyne
At 15:33 17/06/04 -0700, John Meacham wrote: I think it was a couple things, Pattern guards were introduced which were conceptually a whole lot simpler and provided a way to do many of the things views did. http://research.microsoft.com/~simonpj/Haskell/guards.html I like that proposal. In

[Haskell] Replacing and improving pattern guards with PMC syntax

2006-10-01 Thread kahl
uence proof has been mechanised using Isabelle. So far I never considered it important to devise a concrete syntax for PMC, but triggered by the current pattern guards thread on haskell-prime, I now try to give a PMC syntax that blends well with Haskell. PMC ``automatically'' includes the ``e

[Haskell] Re: Replacing and improving pattern guards with PMC syntax

2006-10-02 Thread Claus Reinke
t match failure) can be represented as do-blocks: lhs->rhs ==> \x->do { lhs <- return x; return rhs } (1) and then be composed (the examples I gave moved the \s to the front instead and used "mplus" to compose matchings, but we could also lift the compositions to functi

[Haskell] Re: Replacing and improving pattern guards with PMC syntax

2006-10-03 Thread apfelmus
quot;sugar" become > part of Haskell's core, which thus becomes more complex, > without offering sufficient compensation in terms of expressiveness. I agree. The pattern matching problem is best solved by supplying sugar which either is compositional or fundamental. The composi

[Haskell] Re: Replacing and improving pattern guards with PMC syntax

2006-10-03 Thread apfelmus
I see that <= is already used... Let's take <~ (tilde) instead. A "pseudo-sugared" version in plain Haskell for f (Right (Right p)) = p f (Left p) = p f p = p that is f p = fromJust $ | Right q <~ p | Right r <~ q = r | Left q <~ p = q

[Haskell] Re: Replacing and improving pattern guards with PMC syntax

2006-10-04 Thread Jacques Carette
compose matchings, but we could also lift the compositions to function-level instead), and finally "spliced" back (turning explicit into implicit match failure) using fromJust or suchlike. Adding pattern guards into this translation was straightforward - they simply go between the two

Pattern guards vs. case (was, unfortunately :Re: interesting example of laziness/ghc optimisation)

2001-03-01 Thread Ketil Malde
(Apologies, I forgot to change the subject) Laszlo Nemeth <[EMAIL PROTECTED]> writes: > * * * Ketil Malde <[EMAIL PROTECTED]> wrote: > There is no difference. The 'pipe-syntax' (or pattern guards) gets > desugared (by the pattern matching compiler) to cas

Re: Pattern guards vs. case (was, unfortunately :Re: interesting exampleof laziness/ghc optimisation)

2001-03-01 Thread Johannes Waldmann
> But if you want to be really weird you can write something > like (I haven't typed this in): > > f x | (Foo _) == x = > f x | (Bar _) == x = no, you can't, e. g. hugs (Feb 2000) says Prelude> let f x | Just 4 == x = 0 in f (Just 4) 0 Prelude> let f x | Just _ == x = 0 in f (Just 4) ERROR: I

Re: Pattern guards vs. case (was, unfortunately :Re: interesting exampleof laziness/ghc optimisation)

2001-03-01 Thread Laszlo Nemeth
* * * Johannes Waldmann wrote: > > But if you want to be really weird you can write something > > like (I haven't typed this in): > > > > f x | (Foo _) == x = > > f x | (Bar _) == x = > > no, you can't, e. g. hugs (Feb 2000) says > > Prelude> let f x | Just 4 == x = 0 in f (Just 4) > 0 > Prel

Re: Pattern guards vs. case (was, unfortunately :Re: interesting example of laziness/ghc optimisation)

2001-03-01 Thread John Meacham
On Thu, Mar 01, 2001 at 09:40:48AM +0100, Ketil Malde wrote: > > (Apologies, I forgot to change the subject) > > Laszlo Nemeth <[EMAIL PROTECTED]> writes: > > > * * * Ketil Malde <[EMAIL PROTECTED]> wrote: > > > There is no difference. The 'pipe

Re: Pattern guards vs. case (was, unfortunately :Re: interesting example of laziness/ghc optimisation)

2001-03-01 Thread Laszlo Nemeth
* * * Ketil Malde <[EMAIL PROTECTED]> wrote: > ut - the converse is not true, is it? I can write > > ... = case foo of >(Foo f) -> ... >(Bar b) -> ... > > ut I can't express that as a pattern-guarded expression, can I? You probably have already seen John's

Re: Pattern guards vs. case (was, unfortunately :Re: interesting example of laziness/ghc optimisation)

2001-03-02 Thread Marcin 'Qrczak' Kowalczyk
Thu, 1 Mar 2001 20:25:28 +0900 (KST), Laszlo Nemeth <[EMAIL PROTECTED]> pisze: > > Prelude> let f x | Just _ == x = 0 in f (Just 4) > > ERROR: Illegal `_' in expression > > So it works with (Just 4), but it doesn't with (Just _)? 'Just _ == x' must be an exppression. '_' is a pattern but not an