ML like pattern matching
Greetings, How do I emulate the "when" clause in ML for pattern matching? In other words when a pattern is matched (from a list of patterns of a function) and to enforce additional predicates I use guards, but if the guard condition is not satisfied I want Haskell to get back to trying the remaining patterns. Thanks
Re: ML like pattern matching
Hi Cagdas Ozgenc wrote: Greetings, How do I emulate the "when" clause in ML for pattern matching? In other words when a pattern is matched (from a list of patterns of a function) and to enforce additional predicates I use guards, but if the guard condition is not satisfied I want Haskell to get back to trying the remaining patterns. Thanks Maybe you hav to reorganize the list of patterns or you use "otherwise" as the last case of your guard conditions to call the function with a more general parameters which matches an other pattern. A litle example would be helpfull. Jonas ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: ML like pattern matching
On Fri, 22 Aug 2003 15:49:15 +0300, "Cagdas Ozgenc" <[EMAIL PROTECTED]> wrote: >How do I emulate the "when" clause in ML for pattern matching? In other >words when a pattern is matched (from a list of patterns of a function) and >to enforce additional predicates I use guards, but if the guard condition is >not satisfied I want Haskell to get back to trying the remaining patterns. I may be confused about what you're asking for, but Haskell does this by default: foo (Left x) | x>3 = "bar" foo _ = "splat" Main> foo (Left 5) "bar" Main> foo (Left 1) "splat" Ganesh ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: ML like pattern matching
Thanks. I was reading some codes in ML, and it was commented this was the case. I didn't know Haskell had the equivalent behavior. I always thought once the pattern was matched there is no going back. >> I may be confused about what you're asking for, but Haskell does >> this by default: >> >> foo (Left x) | x>3 = "bar" >> foo _ = "splat" >> >> Main> foo (Left 5) >> "bar" >> Main> foo (Left 1) >> "splat" ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe