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?