问题
I dont understand why the definition of demonbind1 yields some compiler errors. it looks like a stupid flip but somehow..
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes, ScopedTypeVariables, TypeOperators, TypeFamilies,ImpredicativeTypes #-}
type a :-> b = forall i . a i -> b i
class IFunctor f where imap :: (a :-> b) -> (f a :-> f b)
class (IFunctor m) => IMonad m where
skip :: a :-> m a
bind :: (a :-> m b) -> (m a :-> m b)
-- Conor McBride's "demonic bind"
(?>=) :: forall m a b i. (IFunctor m, IMonad m) => m a i -> (a :-> m b) -> m b i
(?>=) =
let
-- OK
demonbind0 = flip (bind :: forall i. (forall j. a j -> m b j) -> m a i -> m b i )
-- KO - see error below
demonbind1 = flip bind :: forall i. m a i -> (forall j. a j -> m b j) -> m b i
-- So i have to write this
demonbind2 :: forall i. (m a i -> (a :-> m b) -> m b i )
demonbind2 mai ti = (bind ti) mai
in demonbind2
The error is
Couldn't match type ‘a j0 -> m b j0’ …
with ‘forall i2. a i2 -> m b i2’
Expected type: (a j0 -> m b j0) -> m a i1 -> m b i1
Actual type: a :-> m b -> m a i1 -> m b i1
In the first argument of ‘flip’, namely ‘bind’
In the expression:
flip bind :: forall i. m a i -> (forall j. a j -> m b j) -> m b i
回答1:
Somewhat surprisingly, ImpredicativeTypes
seem less broken than usual on the development snapshot of GHC 8.0! This compiles without errors:
(?>=) :: (IFunctor m, IMonad m) => m a i -> (a :-> m b) -> m b i
(?>=) = flip bind
I wonder what change fixed the problem.
来源:https://stackoverflow.com/questions/33488322/ranknpolymorphism-and-kleisli-arrows-of-outrageous-fortune