#3660: "Var.tcTyVarDetails" exception w/ Assoc. Datatypes and Monad Transformers
-----------------------------------------------------+----------------------
Reporter:  jfredett                                  |          Owner:          
    Type:  bug                                       |         Status:  new     
Priority:  normal                                    |      Component:  Compiler
 Version:  6.10.4                                    |       Severity:  minor   
Keywords:  Monad Transformers, Associated Datatypes  |       Testcase:          
      Os:  Linux                                     |   Architecture:  x86     
-----------------------------------------------------+----------------------
 Summary:

 When trying to build a monad stack which involves a state transformer with
 a constrained state, the newtype which constrains said state (below, it is
 the `Filter` newtype) cannot seem to derive something within the list of
 things it's intended to derive. After some testing I found that changing
 the `MonadState Bool` part of the `deriving` clause to `MonadState t` (in
 line with the actual state parameter) made everything work. The Type of
 `Email` doesn't matter, I've tested to this effect (replacing `Email` with
 `data Email = Email` and not importing the real version, it still compiles
 fine in the fixed case, and does not compile in the broken case).

 I have not tested on GHC 6.12 yet, I'm still trying to install it. All
 other system information at the bottom.

 By the looks of it, this is a case of GHC not noticing I'm doing something
 silly, and not reporting something along the lines of the "This isn't
 polymorphic enough" error.



 Broken Code:
 {{{
 type Context = ReaderT Email
 type Match t = StateT t IO
 type ContextMatch t a = Context (Match t) a

 newtype FilterState t => Filter t a = Filter (ContextMatch t a)
       deriving (Functor, Monad, MonadReader Email, MonadState Bool,
 MonadIO)

 class FilterState t where
        data FState t
        deliver :: FState t -> IO ()

 }}}

 Error:
 {{{
 [1 of 3] Compiling Network.HackMail.Email.ParseEmail (
 Network/HackMail/Email/ParseEmail.hs, interpreted )
 [2 of 3] Compiling Network.HackMail.Email.Email (
 Network/HackMail/Email/Email.hs, interpreted )
 [3 of 3] Compiling Network.HackMail.Filter.Filter (
 Network/HackMail/Filter/Filter.hs, interpreted )
 *** Exception: No match in record selector Var.tcTyVarDetails
 }}}

 Fixed Code:
 {{{
 type Context = ReaderT Email
 type Match t = StateT t IO
 type ContextMatch t a = Context (Match t) a

 -- changed `Bool` to `t`.
 newtype FilterState t => Filter t a = Filter (ContextMatch t a)
       deriving (Functor, Monad, MonadReader Email, MonadState t, MonadIO)

 class FilterState t where
        data FState t
        deliver :: FState t -> IO ()
 }}}
 System Info:
 {{{
 [jfred...@erdos]$ ghc --version
 The Glorious Glasgow Haskell Compilation System, version 6.10.4
 [jfred...@erdos]$ uname -a
 Linux Erdos 2.6.31-ARCH #1 SMP PREEMPT Fri Oct 23 11:12:58 CEST 2009 i686
 Intel(R) Celeron(R) CPU 3.06GHz GenuineIntel GNU/Linux
 }}}

 (Possibly) Related Tickets include: 3621, 3422 and 2714

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3660>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to