<div dir="auto">Hi Ducis,</div><div dir="auto"><br></div><div dir="auto">> <span style="white-space:pre-wrap;background-color:rgb(255,255,255)">Is it possible to make combine the following "f" and "g" into one function?</span></div><div dir="auto"><span style="white-space:pre-wrap;background-color:rgb(255,255,255)"><br></span></div><div dir="auto"><span style="white-space:pre-wrap;background-color:rgb(255,255,255)">"combine" is vague. You perhaps mean: look at the types of the arguments, and choose one function or the other?</span></div><div dir="auto"><span style="white-space:pre-wrap;background-color:rgb(255,255,255)"><br></span></div><div dir="auto"><span style="font-family:monospace;white-space:pre-wrap;background-color:rgb(255,255,255)">> Looks like it would require some typeclasses,</span><span style="white-space:pre-wrap;background-color:rgb(255,255,255)"><br></span></div><div dir="auto"><span style="white-space:pre-wrap;background-color:rgb(255,255,255)"><br></span></div><div dir="auto"><span style="white-space:pre-wrap;background-color:rgb(255,255,255)">I'll answer the question as put (yes it needs typeclasses), but I can't help feel there's a backstory, and you might well be doing something that could be done better, if I knew what you're trying to achieve. Let's take the second one first</span></div><pre style="white-space:pre-wrap;background-color:rgb(255,255,255)"><div dir="auto">> "eq1" and "eq2" into one function?
> eq1 :: (Eq a)=>a->a->Bool     
> eq1 = (==)                    
> eq2 :: (Eq a,Eq b)=>a->b->Bool
> eq2 _ _ = False               
</div><div dir="auto"><br></div><div dir="auto">class Eqbytype a b  where</div><div dir="auto">  eqt :: a -> b -> Bool</div><div dir="auto"><br></div><div dir="auto">instance {-# OVERLAPPING #-} (Eq a) => Eqbytype a a  where</div><div dir="auto">  eqt = (==)</div><div dir="auto"><br></div><div dir="auto">instance {-# OVERLAPPABLE #-} Eqbytype a b  where</div><div dir="auto">  eqt _ _ = False</div><div dir="auto"><br></div><div dir="auto">Look at the Users Guide for what the OVERLAPPING/OVERLAPPABLE pragmas are doing.</div><div dir="auto"><br></div><div dir="auto">Note for the first instance I repeated type var `a` in the head, meaning: pick this instance if the two arguments to the method are of the same type.</div><div dir="auto"><br></div><div dir="auto">Note for the second instance, I didn't bother with the `Eq` constraint, since we can't compare values of distinct types.</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">> f:: a -> b -> b 
> f x y = y       
> g:: a -> a -> a 
> g x y = x       
<br></div><div dir="auto">So you want same argument types to drive which argument to pick? Or you want the return type to drive which argument? That's possible: look at the definition of class `Read` in the Prelude. Again we can pick instances depending on a repeated type. But your requirements are not clear.</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">> but at least in the first case [which I've put second], "a" and "b" should be any types.
</div><div dir="auto"><br></div><div dir="auto">No they can't: as you state it, you require either all three the same, or the second to be the same as the return type.</div><div dir="auto"><br></div></pre><div dir="auto">Come back and ask a more focussed question once you've worked through the above. (And explain why you're asking.) The above code is untested, BTW.</div><div dir="auto"><br></div><div dir="auto">AntC</div>