gpt4 book ai didi

haskell - 排名多态性和离谱财富的 kleisli 箭头

转载 作者:行者123 更新时间:2023-12-02 01:32:13 24 4
gpt4 key购买 nike

我不明白为什么 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

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

关于haskell - 排名多态性和离谱财富的 kleisli 箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33488322/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com