joeyh

joeyh at

I was wondering if this was actually novel until I got to the part of http://tomasp.net/blog/2014/why-coeffects-matter/ where it says "coeffects correspond to comonads".

I have not yet grokked comonads, but I have seen at least some of what he's using contexts for done with plain old type classes (including monads). For example,

sendResult :: UsesNetwork m => Result -> m Bool

queryDatabase :: Database m => Query -> m Result

answerQuery :: (UsesNetwork m, Database m) => Query -> m Bool
answerQuery q = queryDatabase q >>= sendResult

The type class constraint on sendResult guarantees that, however it's implemented, the only action it can take is network traffic, and the constraint on queryDatabase guarantees that the only action it can take is database access.

Claes Wallin (韋嘉誠), Charles Stanhope likes this.