Can't deduce f = f₁ from f x = f₁ y?

{-# LANGUAGE GADTs #-}

data Foo x y where
  Composition :: Foo b c -> Foo a b -> Foo a c
  FMap :: Functor f => (a->b) -> Foo (f a) (f b)

asFunction :: Foo a b -> a->b
asFunction (FMap m) = fmap m
-- asFunction (Composition (FMap m) (FMap n)) = fmap m . fmap n
asFunction (Composition m n) = asFunction m . asFunction n

This works as expected... until you uncomment the second clause of asFunction ! This is actually just an inlined version of a special case the two other patterns already match, so I'd expect it to be ok. But ( ghc-7.6.2 , or also ghc-7.4.1 )

Could not deduce (f ~ f1)
from the context (b1 ~ f a1, b ~ f b2, Functor f)
  bound by a pattern with constructor
             FMap :: forall (f :: * -> *) a b.
                     Functor f =>
                     (a -> b) -> Foo (f a) (f b),
           in an equation for `asFunction'
  ...

Why does this happen, and why then not in the other clauses? What exactly should be done to prevent this trouble in more complicated applications?


这可能与为了支持更灵活(“不饱和”)类型的功能而暂时从GHC的类型推断系统中删除的特征的左/右分解特征相关,然后当它被发现具有这样的恼人效果时被重新引入。

链接地址: http://www.djcxy.com/p/20024.html

上一篇: LLVM循环优化错误?

下一篇: 无法从fx = f 1 y推导出f = f 1?