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:
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
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 _
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
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.
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