Purescript error - can't match equivalent types?

让人想犯罪 __ 提交于 2019-12-12 02:37:26

问题


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.

Code as below:

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 ) }                                                      

In what circumstances might a '(forall a. a)' be incompatible? (To rephrase the question: What's the difference between a0 and a1 here in the example? I intended these functions to be polymorphic for a)


Update: I now have it working, for the following code:

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}

BUT, I need this to be a javascript-style "Fn2" function, ie, a function that takes two argumetns, and is not curried; and I can't get it to work with Fn2. Any suggestions as to why?

来源:https://stackoverflow.com/questions/43817554/purescript-error-cant-match-equivalent-types

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!