Basically, your type signature says that your function can return a value of any type c given MyEither ab , again, for all a and b . However, as the compiler points out, it is impossible to create such a c here, since you are actually returning a value of type a (being p :: a ).
In addition, your definition still does not control the case when your MyEither ab not Left a . What to do, for example, when calling extractEither (MyRight 1) ? If you try to run such a function (after correcting the typical signature, of course), you may encounter what is called the exclusion pattern exception, which means that there is no body definition for extractEither to identify possible input patterns.
If you are trying to write a single function that works to extract both MyRight and MyRight , I'm afraid you should change your mind. To extract anything you want, left or right, you must have the same type on both sides (i.e. MyEither aa ), which is not so useful.
You must have functions to retrieve values. Here I return Maybe to avoid the burden of managing error calls, for example, when you try to extract the left from the correct value:
extractMyLeft :: MyEither ab -> Maybe a extractMyRight :: MyEither ab -> Maybe b
edit: see also dblhelix answer for a suggestion for another possible refactoring that might be useful for almost getting the type signature you were looking for.
source share