I’m attempting to port some Haskell to PureScript:
-- Haskell
commute :: Foo (a, b) (b, a)
commute = Foo f f where
f (a, b) = Just (b, a)
-- PureScript
commute :: forall a b. Foo (Tuple a b) (Tuple b a)
commute = Foo f f
where
f (Tuple a b) = Just (Tuple b a)
where
data Foo a b = Foo (a -> Maybe b) (b -> Maybe a)
I’m getting this type error:
Could not match type
a0
with type
b1
while trying to match type Tuple t2 t2
with type Tuple a0 b1
while checking that expression (Foo f) f
has type Foo (Tuple a0 b1) (Tuple b1 a0)
in value declaration commute
where b1 is a rigid type variable
bound at line 28, column 11 - line 30, column 35
a0 is a rigid type variable
bound at line 28, column 11 - line 30, column 35
t2 is an unknown type
If I remove the type signature, the inferred type is:
commute :: forall a. Foo (Tuple a a) (Tuple a a)
I’m uncertain as to whether the inferred type is sufficient, and why this doesn’t work if not.