maoe / lifted-async

Run lifted IO operations asynchronously and wait for their results
http://hackage.haskell.org/package/lifted-async
BSD 3-Clause "New" or "Revised" License
29 stars 13 forks source link

Fix 7.10 build #17

Closed sergv closed 9 years ago

sergv commented 9 years ago

Under 7.10 the build was failing with the following error

src/Control/Concurrent/Async/Lifted.hs:384:26:
    Cannot instantiate unification variable ‘b0’
    with a type involving foralls: forall a1. m a1 -> IO (StM m a1)
      Perhaps you want ImpredicativeTypes
    In the first argument of ‘(.)’, namely ‘liftBaseWith’
    In the second argument of ‘(.)’, namely ‘liftBaseWith . const’

For some unknown reason the previous build with 7.10 on CI (https://travis-ci.org/maoe/lifted-async/jobs/56357141) is working, but I've been getting this error with ghc build from 7.10 branch.

maoe commented 9 years ago

By 7.10 branch do you mean ghc-7.10.1-release branch or something else? I think there's no issue with the release version of 7.10.1. I cannot reproduce the error locally or remotely on travis with 7.10.1.

maoe commented 9 years ago

Okay, it seems that GHC has somehow changed after 7.10.1. I just retried the GHC HEAD build and it failed with the same error. Do you know what exactly has changed in GHC? I'd like to understand what's going on before applying this workaround.

maoe commented 9 years ago

If I replace the dots and dollars with parens, it typechecks. Will investigate further later.

diff --git a/src/Control/Concurrent/Async/Lifted.hs b/src/Control/Concurrent/Async/Lifted.hs
index cc1505b..f9dacbe 100644
--- a/src/Control/Concurrent/Async/Lifted.hs
+++ b/src/Control/Concurrent/Async/Lifted.hs
@@ -381,7 +381,7 @@ instance MonadBaseControl IO m => Applicative (Concurrently m) where
     Concurrently $ uncurry ($) <$> concurrently fs as

 instance MonadBaseControl IO m => Alternative (Concurrently m) where
-  empty = Concurrently . liftBaseWith . const $ forever (threadDelay maxBound)
+  empty = Concurrently (liftBaseWith (const (forever (threadDelay maxBound))))
   Concurrently as <|> Concurrently bs =
     Concurrently $ either id id <$> race as bs

diff --git a/src/Control/Concurrent/Async/Lifted/Safe.hs b/src/Control/Concurrent/Async/Lifted/Safe.hs
index c419d4d..cf4ef7d 100644
--- a/src/Control/Concurrent/Async/Lifted/Safe.hs
+++ b/src/Control/Concurrent/Async/Lifted/Safe.hs
@@ -360,7 +360,7 @@ instance (MonadBaseControl IO m, Forall (Pure m)) =>

 instance (MonadBaseControl IO m, Forall (Pure m)) =>
   Alternative (Concurrently m) where
-    empty = Concurrently . liftBaseWith . const $ forever (threadDelay maxBound)
+    empty = Concurrently (liftBaseWith (const (forever (threadDelay maxBound))))
     Concurrently (as :: m a) <|> Concurrently bs =
       Concurrently (either id id <$> race as bs)
         \\ (inst :: Forall (Pure m) :- Pure m a)

Possibly related issue: https://ghc.haskell.org/trac/ghc/ticket/10194

sergv commented 9 years ago

I suspect that impredicativity support was somehow changed. That's what they promise on the wiki anyway, so it's not totally unexpected. And for dollar there's ad-hoc typing rule to facilitate type inference of code like runST $ do ..., so maybe there's some subtle interaction between these.

Anyway, thanks for confirming the bug, it puzzled me a bit why 7.10 on CI was working.

maoe commented 9 years ago

Fixed and released as v0.7.0.1. Thanks for reporting.