[Haskell-cafe] Disjunctive patterns

2011-12-08 Thread Asger Feldthaus
Haskell doesn't seem to support disjunctive patterns, and I'm having a difficult time writing good Haskell code in situations that would otherwise call for that type of pattern. Suppose for an example I have this data type: data T = Foo Int | Bar Int | Baz In OCaml I can write something like:

Re: [Haskell-cafe] Disjunctive patterns

2011-12-08 Thread Serguey Zefirov
2011/12/8 Asger Feldthaus asger.feldth...@gmail.com: Haskell doesn't seem to support disjunctive patterns, and I'm having a difficult time writing good Haskell code in situations that would otherwise call for that type of pattern. Suppose for an example I have this data type: data T = Foo

Re: [Haskell-cafe] Disjunctive patterns

2011-12-08 Thread Emil Axelsson
Instead of pattern guards you can use ViewPatterns: http://hackage.haskell.org/trac/ghc/wiki/ViewPatterns This reduces some of the noise. {-# LANGUAGE ViewPatterns #-} data T = Foo Int | Bar Int | Baz fooBar (Foo a) = Just a fooBar (Bar a) = Just a fooBar _

Re: [Haskell-cafe] Disjunctive patterns

2011-12-08 Thread Øystein Kolsrud
Or perhaps this? data T = Foo Int | Bar Int | Baz fooBar (Foo a) = Just a fooBar (Bar a) = Just a fooBar _ = Nothing foo :: T - T - Int foo x y = sum $ catMaybes $ map fooBar [x,y] /Øystein On Thu, Dec 8, 2011 at 1:15 PM, Emil Axelsson e...@chalmers.se wrote: Instead of pattern guards

Re: [Haskell-cafe] Disjunctive patterns

2011-12-08 Thread David Waern
2011/12/8 Asger Feldthaus asger.feldth...@gmail.com: Haskell doesn't seem to support disjunctive patterns, and I'm having a difficult time writing good Haskell code in situations that would otherwise call for that type of pattern. I've also missed this after having done a bit of OCaml coding.

Re: [Haskell-cafe] Disjunctive patterns

2011-12-08 Thread Holger Siegel
Am 08.12.2011 um 11:13 schrieb Asger Feldthaus: Haskell doesn't seem to support disjunctive patterns, and I'm having a difficult time writing good Haskell code in situations that would otherwise call for that type of pattern. In Haskell I can't find any equivalent to the disjunctive