[Haskell-cafe] Monad transformer responsibilities

David Menendez dave at zednenem.com
Fri Jun 5 08:21:52 EDT 2009


On Fri, Jun 5, 2009 at 7:25 AM, Claus Reinke <claus.reinke at talk21.com> wrote:
>
> If ProjectPackage actually depends on the existence of those orphan
> instances, plan B is to delay instance resolution, from library to clients,
> so instead of importing the orphan instances
>
> module ProjectPackage where import MyMonadT_Parsec
> f .. =  .. orphan instances are available, use them ..
>
> (which leads to the dreaded implicit export), you'd just assert their
> existence:
>
> module ProjectPackage where f :: .. Orphan x => .. ; f .. = .. use orphan
> instances ..

That gets awkward if you're dealing with a concrete type. Consider,

class C a where
	foo :: a -> a

data T = T

bar :: C T => T
bar = foo T

I was able to get GHCi to accept this with FlexibleContexts, but it
obviously doesn't like it.

*Main> :bro Main
class C a where foo :: a -> a
data T = T
bar :: (C T) => T
*Main> :t bar

<interactive>:1:0:
    No instance for (C T)
      arising from a use of `bar' at <interactive>:1:0-2
    Possible fix: add an instance declaration for (C T)
    In the expression: bar

But at least it's possible. And the problems go away once the instance
is in scope.

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>


More information about the Haskell-Cafe mailing list