[Haskell-cafe] Pattern match question in HAXML code

Max Cantor mxcantor at gmail.com
Sat May 23 17:19:36 EDT 2009

Going through the instances for HTypeable (http://www.haskell.org/HaXml/HaXml/src/Text/XML/HaXml/TypeMapping.html#toHType 
) I saw the following instance for Either a b.

My question is, why doesn't the pattern match in the where clause  
always fail?  If (Left x) = m does not fail, doesn't that imply that m  
is a Left x and therefore the (Right y) = m should fail?

thanks, max

instance (HTypeable a, HTypeable b) => HTypeable (Either a b) where
   toHType m      = Defined "Either" [hx, hy]
                        [ Constr "Left" [hx] [hx] {-Nothing-}
                        , Constr "Right" [hy] [hy] {-Nothing-}]
                  where (Left x)  = m
                        (Right y) = m
                        hx = toHType x
                        hy = toHType y

More information about the Haskell-Cafe mailing list