Hi all,
I'm struggling with one complex problem for quite some time. This is the minimal code that throws an error:
import Control.Category
data MyType p a b
= MyInstance p a b deriving (Show, Eq)
myTypeComposition :: MyType q b c -> MyType p a b -> MyType (p, q) a c
myTypeComposition (MyInstance q _ c) (MyInstance p a _) = MyInstance (p, q) a c
instance Category (MyType p) where
(.) = myTypeComposition
I'm trying to define the composition function for the typeclass
Control.Category.
My data type MyType p a b can be thought of as a function form a to b that is parametrized by p.
I want to be able to define many MyTypes and compose them as needed (the actual code has more complex logic, which I removed I so the problem is more obvious). I can compose MyTypes with no problem with the myTypeComposition function I've defined, but I can't use that function as the composition in the Category class.
The problem seems to be in the fact that the result of the composition is of type (p, q) a c. The compiler expects the type p a c, even though that parameter p is not really needed for defining a Category. I do have to put p in when instantiating my type as to make the kinds match, but then compiler expects the result also to be p, which I don't really want.
Any ideas, thoughts? This seems to be a really niche case and I can't find anything useful in google.
--
Bruno Gavranović
Faculty of electrical engineering and computing | Fakultet elektrotehnike i računarstva
Zagreb, Croatia
mobile phone: +385 91 755 8798