以下代码将无法编译:
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
bad :: V.Vector Int
bad = id . V.create $ do
v <- MV.new 1
MV.set v 0
pure v
• Couldn't match type ‘m0 (MV.MVector (Control.Monad.Primitive.PrimState m0) a0)’ with ‘forall s. GHC.ST.ST s (MV.MVector s Int)’ Expected type: m0 (MV.MVector (Control.Monad.Primitive.PrimState m0) a0) -> V.Vector Int Actual type: (forall s. GHC.ST.ST s (MV.MVector s Int)) -> V.Vector Int • In the second argument of ‘(.)’, namely ‘V.create’ In the expression: id . V.create In the expression: id . V.create $ do { v <- MV.new 1; MV.set v 0; pure v }
但接下来将是:
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
good :: V.Vector Int
good = id $ V.create $ do
v <- MV.new 1
MV.set v 0
pure v
stack
解析器是lts-9.12
那么,如果我喜欢按(.)
撰写,为什么会这样做以及如何修复?
答案 0 :(得分:9)
你已经发现GHC无法做出不可预测的多态性这一事实。 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart');
// get cart items
$items = $cart->getItems();
$isyes="0";
// get product attribute value of cart items
foreach ($items as $item){
if(!$item->getData('test')=="yes"){
$isyes="1";
}
};
if($isyes=="1"){
unset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingAddress']['children']['shipping-address-fieldset']['children']['test']);
}
的排名类型V.create
较高,当您尝试将其应用于forall a. Unbox a => (forall s. ST s (MVector s a)) -> Vector a
时,您最终需要实例化(id .) :: (x -> y) -> (x -> y)
,这会爆炸。并不是说有任何真正错误的所需的实例化;只是GHC无法处理它。曾经有一个扩展名x = forall s. ST s (MVector s a)
试图提供有限的支持,但是从GHC 8开始,它已经被彻底破坏和弃用了。 ImpredicativePolymorphism
仍然有效的原因是因为它实际上已经硬连线到GHC中,因此它可以避免这个问题,这就是为什么如果你试图定义
($)
并在f $$ x = f x
处使用它而不是($)
。