{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE Arrows #-}
Given some constraint Foo
, I would like to use the rebindable arrow do-notation in FooArrow
s: where types satisfy Foo
. We can only lift arrows between Foo
types and we can only tensor them using first
if they are foo
types.
class FooArrow hom where
arr :: (Foo a) => (a -> b) -> hom a b
(>>>) :: (Foo a, Foo b, Foo c) => hom a b -> hom b c -> hom a c
first :: (Foo a, Foo b, Foo c) => hom a b -> hom (a, c) (b, c)
returnA :: (FooArrow hom, Foo a) => hom a a
returnA = arr (\a -> a)
And everything compiles fine until here. However, when actually using the notation, the compiler will complain that • Could not deduce (Foo b1) arising from a use of ‘first’
, even in contexts where I think I have already provided all of the Foo
constraints.
swap :: (FooArrow hom, Foo a, Foo b) => hom (a,b) (b,a)
swap = proc (a , b) ->
returnA -< (b, a)
class Foo a where
instance Foo () where
instance (Foo a, Foo b) => Foo (a , b) where
Why am I getting this error? Am I missing something to make this work? Is it possible at all to get constrained arrow do-notation?