Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell RankNpolymorphism和kleisli狂暴命运之箭_Haskell_Polymorphism - Fatal编程技术网

Haskell RankNpolymorphism和kleisli狂暴命运之箭

Haskell RankNpolymorphism和kleisli狂暴命运之箭,haskell,polymorphism,Haskell,Polymorphism,我不明白为什么demonbind1的定义会产生一些编译器错误。这看起来像一个愚蠢的翻转,但不知怎么的 {-# LANGUAGE GADTs #-} {-# LANGUAGE RankNTypes, ScopedTypeVariables, TypeOperators, TypeFamilies,ImpredicativeTypes #-} type a :-> b = forall i . a i -> b i class IFunctor f where imap :: (

我不明白为什么demonbind1的定义会产生一些编译器错误。这看起来像一个愚蠢的翻转,但不知怎么的

{-# 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
错误是

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

有些令人惊讶的是,
ImpredicativeTypes
在GHC 8.0的开发快照上似乎没有像往常那样坏!编译时不会出现错误:

(?>=) :: (IFunctor m, IMonad m) => m a i -> (a :-> m b) -> m b i
(?>=) = flip bind

我想知道是什么改变解决了这个问题。

这是重复的,对不起……事实上,它不是完全重复的。在最初的问题中,唯一不起作用的是
do
notation。但如今,GHC的
ImpredicativeTypes
扩展几乎根本不起作用,因此代码中的所有内容都会中断。即使使用了
demonbind2
定义,我想您也会发现很难使用
(?>)
.true,而不是真正的重复。我将继续手动扩展。那真是一个小小的伤害。现在最让人恼火的是,你会期望这样简单的操作能开箱即用。不,我也不会把它称为复制品。重新开放。这是令人惊讶的,而且,我认为,大多数情况下不是这样。我记得有人提到一些新的
ImpredicativeTypes
brokenness。理查德·艾森伯格(Richard Eisenberg)最近对类型系统进行了一些重大更改,他回答说,他没有采取任何措施来避免对已经损坏的扩展进行进一步的破坏。@d因为我没有说,
ImpredicativeTypes
现在可以工作了。我只是说它们看起来没那么破碎,这是完全不同的说法。在得到适当的修复之前,它们肯定不应该被使用。从积极的方面来看,似乎正在努力使它们工作: