如何统一c和GHC.Exts.Item t c?

时间:2015-04-08 13:48:08

标签: haskell ghc

我刚刚更新了dynamic time warping library以使用ghc-7.10进行编译,并偶然发现了一个奇怪的问题:

ghc-7.8中编译良好的代码:

{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE TypeFamilies #-}
dtwNaive :: (Ord c, Fractional c, DataSet a, DataSet b)
         => (Item a -> Item b -> c) -> a -> b -> c
dtwNaive δ as bs = go (len as - 1) (len bs - 1)
    where go 0 0 = 0
          go _ 0 = 1/0
          go 0 _ = 1/0
          go x y = δ (ix as x) (ix bs y) + minimum [ go (x-1)  y
                                                   , go  x    (y-1)
                                                   , go (x-1) (y-1)
                                                   ]

现在产生以下错误:

src/Data/DTW.hs:112:52:
    Couldn't match type ‘c’ with ‘GHC.Exts.Item (t1 c)’
      ‘c’ is a rigid type variable bound by
          the type signature for
            dtwNaive :: (Ord c, Fractional c, DataSet a, DataSet b) =>
                        (Item a -> Item b -> c) -> a -> b -> c
          at src/Data/DTW.hs:106:13
    Expected type: Int -> [c] -> t1 c
      Actual type: Int -> [GHC.Exts.Item (t1 c)] -> t1 c
    Relevant bindings include
      go :: Int -> Int -> c (bound at src/Data/DTW.hs:109:11)
      δ :: Item a -> Item b -> c (bound at src/Data/DTW.hs:108:10)
      dtwNaive :: (Item a -> Item b -> c) -> a -> b -> c
        (bound at src/Data/DTW.hs:108:1)
    In the first argument of ‘minimum’, namely
      ‘[go (x - 1) y, go x (y - 1), go (x - 1) (y - 1)]’
    In the second argument of ‘(+)’, namely
      ‘minimum [go (x - 1) y, go x (y - 1), go (x - 1) (y - 1)]’
    In the expression:
      δ (ix as x) (ix bs y)
      + minimum [go (x - 1) y, go x (y - 1), go (x - 1) (y - 1)]

我真的很困惑,因为我认为[c][GHC.Exts.Item (t c)] t ~ []时的{{1}}相同。我错过了什么?

1 个答案:

答案 0 :(得分:3)

minimum的类型与以前不同。旧类型为Ord a => [a] -> a。新类型为(Ord a, Foldable t) => t a -> a

IsList的参数列表文字有一个minimum实例不再明显了。您可以通过添加本地注释来解决此问题:

{-# LANGUAGE ScopedTypeVariables #-}
dtwNaive :: 
            forall a b c.
            (Ord c, Fractional c, DataSet a, DataSet b)
         => (Item a -> Item b -> c) -> a -> b -> c
dtwNaive = ...
    minimum ([go (x-1) y, go x (y-1), go (x-1) (y-1)] :: [c])