为什么编译器对同构类型生气?
Why compiler is getting angry with isomorphic types?
Expected type: ErrorT String IO Integer
Actual type: IO (Either String Integer)
我不知道我哪里错了。毕竟这些类型是同构的。
当然,当我从
替换我的函数签名时
ErrorT String IO Integer
到
IO (Either String Integer)
编译器高兴,我不高兴,因为我糊涂了
回答起来有点棘手,因为没有真正的问题,但编译器不满意,因为类型可能 同构 但它们不是同义词 - 有一个 ErrorT
在途中:
newtype ErrorT e m a = ErrorT m (Either e a)
^^^^^^
您已经在另一个问题中提出了这一点 - 这是
之类的东西之间的区别
return (Left "Hello") :: IO (Either String Integer)
和
ErrorT (return (Left "Hello")) :: ErrorT String IO Integer
Expected type: ErrorT String IO Integer
Actual type: IO (Either String Integer)
我不知道我哪里错了。毕竟这些类型是同构的。
当然,当我从
ErrorT String IO Integer
到
IO (Either String Integer)
编译器高兴,我不高兴,因为我糊涂了
回答起来有点棘手,因为没有真正的问题,但编译器不满意,因为类型可能 同构 但它们不是同义词 - 有一个 ErrorT
在途中:
newtype ErrorT e m a = ErrorT m (Either e a)
^^^^^^
您已经在另一个问题中提出了这一点 - 这是
之类的东西之间的区别return (Left "Hello") :: IO (Either String Integer)
和
ErrorT (return (Left "Hello")) :: ErrorT String IO Integer