[Haskell-cafe] Pattern match question in HAXML code

Miguel Mitrofanov miguelimo38 at yandex.ru
Sat May 23 17:43:15 EDT 2009


On 24 May 2009, at 01:19, Max Cantor wrote:

> 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?

It does; at least one of x and y is (_|_). However, toHType function  
doesn't really need it's argument; all that is needed is the type of  
an argument. Therefore, toHType is quite happy to receive (_|_) as an  
argument - so, hx and hy are well-defined.

>
>
> 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
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list