スタック・オーバーフローに参加する
684万人以上のプログラマーが集まるスタック・オーバーフローに参加しませんか?
簡単な登録後、すぐにご利用いただけます。
登録

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
share|improve this question
    
its a duplicate, sorry.. – nicolas Nov 2 '15 at 22:42
    
Actually, it is not quite a duplicate. In the original question the only thing that wasn't working was do notation. But nowadays, GHC's ImpredicativeTypes extension almost doesn't work at all, so everything in the code breaks. Even with your demonbind2 definition, I think you will find it very hard to use (?>=). – Ørjan Johansen Nov 2 '15 at 23:35
    
true, not really a duplicate. I'll go on with manual expansion. That's really a minor harm. what is annoying on the moment is that you'd expect such simple operation to work out of the box. – nicolas Nov 3 '15 at 9:04
    
Nope, I wouldn't call it a duplicate either. Reopened. – dfeuer Feb 3 '16 at 23:02

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.

share|improve this answer
1  
That's surprising and also, I think, mostly not the case. I remember someone mentioning some new ImpredicativeTypes brokenness. Richard Eisenberg, who's made some major changes to the type system recently, responded that he'd made no effort whatsoever to avoid further breakage to that already-broken extension. – dfeuer Mar 23 '16 at 1:20
    
@dfeuer I didn't say that ImpredicativeTypes work now. I've only said that they seem less broken, and that's a completely different statement. They surely shouldn't be used until they get a proper fix. – int_index Mar 23 '16 at 1:25
2  
On a positive note, there appears to be some work happening towards making them work: ghc.haskell.org/trac/ghc/raw-attachment/wiki/… – int_index Mar 23 '16 at 1:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.