Compiler errors PureScript无法匹配相同的受约束类型

Compiler errors PureScript无法匹配相同的受约束类型,compiler-errors,purescript,Compiler Errors,Purescript,我想知道为什么PureScript无法匹配两种受约束的类型,即字符对字符,相同!请参阅下面的错误消息。产生它的代码如下所示: -- We are using https://pursuit.purescript.org/packages/purescript-sized-vectors/1.0.0 import Data.Typelevel.Num (class Lt, class Nat, D2, D7) import Data.Vec (Vec, modifyAt) import Prelu

我想知道为什么PureScript无法匹配两种受约束的类型,即字符对字符,相同!请参阅下面的错误消息。产生它的代码如下所示:

-- We are using https://pursuit.purescript.org/packages/purescript-sized-vectors/1.0.0
import Data.Typelevel.Num (class Lt, class Nat, D2, D7)
import Data.Vec (Vec, modifyAt)
import Prelude (($))

newtype FixedMatrix72 a = FixedMatrix72 (Vec D2 (Vec D7 a))

type Row = forall n. (Nat n, Lt n D2) => n
type Col = forall n. (Nat n, Lt n D7) => n
newtype Ref = Ref { row :: Row, col :: Col }

-- Compiler error is for this function
modify :: forall a. Ref -> (a -> a) -> FixedMatrix72 a -> FixedMatrix72 a
modify (Ref ref) f (FixedMatrix72 m) =
 FixedMatrix72 $ modifyAt ref.row (modifyAt ref.col f) m
编译器错误:

    Could not match constrained type

      ( Nat t0  
      , Lt t0 D2
      ) => t0   

    with type

      ( Nat t0  
      , Lt t0 D2
      ) => t0   


  while trying to match type ( Nat t0  
                             , Lt t0 D2
                             ) => t0   
    with type ( Nat t0  
              , Lt t0 D2
              ) => t0   
  while solving type class constraint

    Data.Typelevel.Num.Ops.Lt (( Nat t0  
                               , Lt t0 D2
                               ) => t0   
                              )          
                              D2         

  while checking that expression \$0 ->               
                                   \f ->              
                                     \$1 ->           
                                       case $0 f $1 of
                                         ...          
    has type forall a. Ref -> (a -> a) -> FixedMatrix72 a -> FixedMatrix72 a
  in value declaration modify

  where t0 is an unknown type

  See https://github.com/purescript/purescript/wiki/Error-Code-ConstrainedTypeUnified for more information,
  or to contribute content related to this error.

错误消息不是很好,但它并不是说类型不可统一。这意味着编译器永远不会尝试统一受约束的类型,因为传递正确的字典会变得复杂。因此,如果我们在类型检查器中达到这一点,我们将放弃并显示此错误消息

幸运的是,它只出现在非常特定的情况下,涉及类型系统特征之间的各种交互(在本例中,记录的字段类型是多态的,并且涉及类型类)

一种解决方案是使用
newtype
s而不是类型同义词