Wednesday, August 29, 2012

rpc-framework #1: Contravariance & Typeclasses

Suppose we have a typeclass:
 class Sendable a b | a -> b, b -> a where  
   send :: a -> IO ()  
   receive :: IO b  
Ideally we should have an instance for functions:
 class (Sendable a' a, Sendable b b') => Sendable (a -> b) (a' -> IO b') where  
This has contravariant narrowing though. Down the line, it will run into problems. Solution: split sendable into two definitions, one for sendable and one for receivable.

No comments:

Post a Comment

1. Do be civil.
2. Reasonable criticisms are welcome, but personal opinions are not.
3. These posts are not for evangelizing languages, but for contemplating interesting properties.