Purescript错误 - 无法匹配等效类型?

时间:2017-05-06 06:41:02

标签: purescript

Error found:
in module Test
at /Users/arahael/dev/test/test.purs line 14, column 37 - line 14, column 59

  Could not match constrained type

    (Spreadable a0) => Array a0 -> Int

  with type

    (Spreadable a1) => Array a1 -> Int


while trying to match type (Spreadable a0) => Array a0 -> Int
  with type (Spreadable a1) => Array a1 -> Int
while checking that expression mkFn2 get_biscuits
  has type Fn2 String (forall a. (Spreadable a) => Array a -> Int) Int
in value declaration packetMaker

where a1 is a rigid type variable
      a0 is a rigid type variable

See https://github.com/purescript/documentation/blob/master/errors/ConstrainedTypeUnified.md for more information,
or to contribute content related to this error.

代码如下:

module Test                                                                                                            
where                                                                                                                  


foreign import data Fn2 :: * -> * -> * -> *                                                                            
foreign import mkFn2 :: forall a b c. (a -> b -> c) -> Fn2 a b c                                                       

class Spreadable a

newtype Packet = Packet { getBiscuits :: Fn2 String (forall a. (Spreadable a) => Array a -> Int) Int }

get_biscuits :: String -> (forall a. (Spreadable a) => Array a -> Int) -> Int
get_biscuits _ _ = 42
packetMaker = Packet { getBiscuits: mkFn2 ( get_biscuits ) }                                                      

在什么情况下可能会出现这样的情况。不相容? (重新解释一下这个问题:示例中a0和a1之间的区别是什么?我打算将这些函数变为多态的a)

更新:我现在可以使用它,代码如下:

module Test
where

class Spreadable a

newtype Packet = Packet { getBiscuits :: String -> (forall a. (Spreadable a) => Array a -> Int) ->  Int }

get_biscuits :: String -> (forall a. (Spreadable a) => Array a -> Int) -> Int
get_biscuits _ _ = 42

packetMaker :: Packet
packetMaker = Packet { getBiscuits: \a b -> get_biscuits a b}

但是,我需要这是一个javascript风格的" Fn2"功能,即一个需要两个参数的功能,而不是咖喱;而我无法与Fn2合作。有什么建议吗?

0 个答案:

没有答案