
9 Nov
2013
9 Nov
'13
6:46 p.m.
Hi, I'm wondering if there's some way to express that a function can be composed with itself at the type level. Due to polymorphism this is not quite the same as saying that the domain and co-domain match. Example: swap :: (a, b) -> (b, a) swap . swap :: (a, b) -> (a, b) I'd like to write a function such as (in pseudocode): involute :: ((a -> b) &&& (b -> a)) -> (a -> a) involute f = f . f But I obviously can't write down the type for (a -> b) &&& (b -> a) Perhaps this can be done with some typeclass hackery? -- Ignas