<div dir="ltr"><div><div><div><div><div>Hi devs,<br></div><br></div>could you please have a look at the following code snippet (modeled after a real-world app of mine)? There's a rank2type involved, and it doesn't type-check anymore when the type is e.g. part of a tuple, whereas everything's fine when it's the "outermost" type.<br><br></div>With GHC7.10 both variants type-check. Could anyone shed some light on what's behind this? Is the way the types are used in the snippet considered dispreferred or wrong under GHC8?<br><br></div>Thanks for having a look and hopefully pointing me to a page/ticket/... providing insight,<br></div>Michael<br><br>--------<br><span style="font-family:monospace,monospace"><br>{-# LANGUAGE Rank2Types #-}<br><br>module TestTypes where<br><br>data State a        = State a<br><br>data Dummy          = Dummy<br><br>type Handler result = forall state . State state -> IO result<br><br>type Resolver       = String -> Handler String<br><br><br>eventRouter :: Resolver -> String -> IO ()<br>eventRouter resolver event =<br>    resolver event state >> return ()<br>  where<br>    state :: State ()<br>    state = undefined<br><br>{-<br>-- does type check<br>createResolver :: Resolver<br>createResolver = \event state -> return "result"<br><br>processor :: IO ()<br>processor =<br>    getLine >>= eventRouter resolver >> processor<br>  where<br>    resolver = createResolver<br>-}<br><br><br>-- does not type check when the rank 2 type isn't the "outermost" one?<br>createResolver :: (Resolver, Dummy)<br>createResolver = (\event state -> return "result", Dummy)<br><br>processor :: IO ()<br>processor =<br>    getLine >>= eventConsumer resolver >> processor<br>  where<br>    (resolver, _) = createResolver<br><br>{-<br>    • Couldn't match type ‘t’ with ‘Resolver’<br>      ‘t’ is a rigid type variable bound by<br>        the inferred type of resolver :: t at TestTypes.hs:41:5<br>      Expected type: (t, Dummy)<br>        Actual type: (Resolver, Dummy)<br>-}<br></span><span style="font-family:monospace,monospace"></span><br><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace"></span><div><div><br></div></div></div>