<div dir="ltr"><div>Hello All,<br><br>I am working on a program that will define a bunch of tasks. Each task<br>will have to implement certain methods as part of a type class.<br><br>-- task 1<br>data UpdateAcctsTask = UpdateAccts<br><br>-- task 2<br>data EmailConfig = EmaiConfig {someattrs::String}<br>data SendEmailTask = SendEmailsTask EmailConfig<br><br>-- task 3<br>data GeneralWriterTask a = GeneralWriterTask a<br><br>Each of these tasks implement a class, Taskable. The return<br>values are simplified for this example.<br><br>class Taskable a where<br>  process :: a -> Bool<br>  can_run :: a -> Bool<br><br><br>This works fine. I can expand on these tasks and execute them.<br><br>Now, I wanted to be able to defined dependencies between these (Taskable's). I decided<br>I could create a data type for this dependency and may be also get a FreeMonad<br>around this structure for further processing using a graph of Tasks. But, before that I wanted<br></div>to create an wrapper for these Taskables and create a functor for it as follows<br><div><br>The first thing I did was, define a Task, which generalizes over all<br>the above defined (and future Taskables)<br><br>data Task a where<br>  Task :: (Taskable a) => a -> Task a<br><br><br>instance Functor Task where<br>  fmap:: (Taskable a, Taskable b) -> (a -> b) -> Task a  -> Task b    --- THIS DOES NOT WORK<br>  fmap f (Task a) = Task $ f a<br><br><br>But, I realized that I cannot define an fmap over a type constraint.<br><br>My questions are:<br><br>1. Is there any way to do this. I see there is an answer of SO. I wanted<br>   to make sure if there were any improvements to this since that answer'<br>   was posted. <br>   <a href="http://stackoverflow.com/questions/17157579/functor-instance-for-a-gadt-with-type-constraint">http://stackoverflow.com/questions/17157579/functor-instance-for-a-gadt-with-type-constraint</a><br><br>2. Secondly, I would like to know why this is not possible. Is it a current<br>   limitation of GHC or if there is some fundamental category theory concepts<br>   that dis-allows such declarations that I need to grok!<br><br></div>Appreciate any help on this. Thank you!<br></div>