I’m using free monad to structure my application. I thought that it would be a good idea to generalize the middle layer to make it more reusable. Long story short I want to make this:
data TeletypeF n = DbFindPayin (Pg.Query (Pg.Row1 PayinId) (Pg.Row1 Payin)) PayinId (Maybe Payin -> n) | DbFindPayout (Pg.Query (Pg.Row1 PayoutId) (Pg.Row1 Payout)) PayoutId (Maybe Payout -> n) | DbUpdatePayin ... instance functorTeletypeF :: Functor TeletypeF where map f (DbFindPayin query params next) = DbFindPayin query params (next >>> f) map f (DbFindPayout query params next) = DbFindPayout query params (next >>> f) ... type Teletype = Free TeletypeF
into something like this (where I can have just 1 constructor for every type of database operation):
data TeletypeF i o e next = DbFindOne (Pg.Query i o) i (Maybe o -> next) | DbUpdateOne (Pg.Query i o) i next | ... instance functorTeletypeF :: Functor (TeletypeF i o e) where map f (DbFindOne query params next) = DbFindOne query params (next >>> f) map f (DbUpdateOne query params next) = DbUpdateOne query params (f next) type Teletype i o e = Free (TeletypeF i o e)
The problem is when I try to use it, I get
Could not match type Row1 PayoutId with type i'0 errors.
Can I actually parametrize my functor like that to work with different queries? Thanks for any help.