RankNpolymorphism和kleisli箭头的离谱财富 [英] RankNpolymorphism and kleisli arrows of outrageous fortune

查看:104
本文介绍了RankNpolymorphism和kleisli箭头的离谱财富的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  { - #LANGUAGE GADTs# - } 
{ - #LANGUAGE RankNTypes,ScopedTypeVariables,TypeOperators,TypeFamilies,ImpredicativeTypes# - }

类型a: - > b =全部我。一个i - > b i

class IFunctor f where imap ::(a: - > b) - > (f a: - > f b)

class(IFunctor m)=> IMonad m其中
skip :: a: - > m a
bind ::(a: - > m b) - > (m a: - > m b)


- Conor McBride的恶魔绑定
(?> =):: forall m a b i。 (IFunctor m,IMonad m)=> m a i - > (a: - > m b) - > mbi
(?> =)=
let
- OK
demonbind0 = flip(bind :: forall i。(forall j。aj - > mbj) - > ; mai - > mbi)
- KO - 在
下面看到错误demonbind1 = flip bind :: forall i。 m a i - > (所有j,a j - > m b j) - > m b我

- 所以我必须写这个
demonbind2 :: forall i。 (mai - >(a: - > mb) - > mbi)
demonbind2 mai ti =(bind ti)mai
in demonbind2
pre>

错误是

 无法匹配类型'a j0  - > m b j0'... 
与'forall i2。一个i2 - > (a j0→m b j0)→ m a i1 - > m b i1
实际类型:a: - > m b - > m a i1 - > m b i1
在'flip'的第一个参数中,即'bind'
在表达式中:
flip bind :: forall i。 m a i - > (所有j,a j - > m b j) - > mbi


解决方案

有点令人惊讶的是, ImpredicativeTypes 在GHC 8.0的开发快照中似乎比平时更少破碎!这个编译没有错误:

 (?> =)::(IFunctor m,IMonad m)=> m a i  - > (a: - > m b) - > mbi 
(?> =)=翻转绑定


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

解决方案

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.

这篇关于RankNpolymorphism和kleisli箭头的离谱财富的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆