20 May 00:09 2013

## More general "pattern matching"

Tom Ellis <tom-lists-haskell-cafe-2013 <at> jaguarpaw.co.uk>

2013-05-19 22:09:15 GMT

2013-05-19 22:09:15 GMT

Suppose I have a Category C > import Prelude hiding ((.), id) > import Control.Category > > data C a b > > instance Category C where > (.) = undefined > id = undefined which has "products" in the sense that there exists a "factors" function with suitable properties > factors :: C a (b, c) -> (C a b, C a c) > factors = undefined Then I can define this interesting combinator > (~~) :: (C a b -> r) -> (C a c -> r') -> C a (b, c) -> (r, r') > (f ~~ g) h = let (l, r) = factors h in (f l, g r) which allows some form of "pattern matching", for example > a :: C z a > b :: C z b > c :: C z c > d :: C z d > e :: C z e > ((a, b), (c, (d, e))) = ((id ~~ id) ~~ (id ~~ (id ~~ id))) undefined(Continue reading)