Hi the attached module is a much reduced version of some type-level assurance stuff (inspired by the Lightweight Monadic Regions paper) I am trying to do. I am almost certain that it could be reduced further but it is late and I want to get this off my desk.
Note the 4 test functions, test11 .. test14. The following are timings for compiling the module only with all test functions commented out, except respectively, test11, test12, test13, and test14: b...@sarun[1] > time ghc -c Bug2.hs ghc -c Bug2.hs 1,79s user 0,04s system 99% cpu 1,836 total b...@sarun[1] > time ghc -c Bug2.hs ghc -c Bug2.hs 5,87s user 0,14s system 99% cpu 6,028 total b...@sarun[1] > time ghc -c Bug2.hs ghc -c Bug2.hs 23,52s user 0,36s system 99% cpu 23,899 total b...@sarun[1] > time ghc -c Bug2.hs ghc -c Bug2.hs 102,20s user 1,32s system 97% cpu 1:45,89 total It seems something is scaling very badly. You really don't want to wait for a version with 20 levels of nesting to compile... If anyone has a good explanation for this, I'd be grateful. BTW, I am not at all certain that this is ghc's fault, it may well be my program, i.e. the constraints are too complex, whatever. I have no idea how hard it is for the compiler to do all the unification. Also, the problem is not of much practical relevance, as no sensible program will use more than a handfull levels of nesting. Cheers Ben
{-# LANGUAGE Rank2Types, TypeSynonymInstances #-} {-# LANGUAGE TypeFamilies, GeneralizedNewtypeDeriving #-} module Bug2 where import Control.Monad.Reader newtype ResourceT r s m v = ResourceT { unResourceT :: ReaderT r m v } deriving (Monad) data Ctx = Ctx data Ch = Ch type CAT s c = ResourceT [Ch] (s,c) type CtxM c = ResourceT Ctx c IO newtype CA s c v = CA { unCA :: CAT s c (CtxM c) v } deriving (Monad) class (Monad m) => MonadCA m where type CtxLabel m instance MonadCA (CA s c) where type CtxLabel (CA s c) = c instance (Monad m, MonadCA m, c ~ CtxLabel m) => MonadCA (CAT s c m) where type CtxLabel (CAT s c m) = c runCAT :: (forall s. CAT s c m v) -> m v runCAT action = runReaderT (unResourceT action) [] newRgn :: MonadCA m => (forall s. CAT s (CtxLabel m) m v) -> m v newRgn = runCAT runCA :: (forall s c. CA s c v) -> IO v runCA action = runCtxM (runCAT (unCA action)) runCtxM :: (forall c. CtxM c v) -> IO v runCtxM action = runReaderT (unResourceT action) Ctx test11 :: IO () test11 = runCA(newRgn(newRgn(newRgn(newRgn(newRgn( newRgn(newRgn(newRgn(newRgn(return())))))))))) -- test12 :: IO () -- test12 = runCA(newRgn(newRgn(newRgn(newRgn(newRgn(newRgn( -- newRgn(newRgn(newRgn(newRgn(return()))))))))))) -- test13 :: IO () -- test13 = runCA(newRgn(newRgn(newRgn(newRgn(newRgn(newRgn(newRgn( -- newRgn(newRgn(newRgn(newRgn(return())))))))))))) -- test14 :: IO () -- test14 = runCA(newRgn(newRgn(newRgn(newRgn(newRgn(newRgn(newRgn(newRgn( -- newRgn(newRgn(newRgn(newRgn(return())))))))))))))
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users