Tom Ellis | 20 May 00:09 2013
Picon

More general "pattern matching"

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)


Gmane