<div dir="ltr">Lets say I've got the following data type:<div><br></div><div>data D c a b = D (c a b) (c b a)</div><div><br></div><div>And I define a function to manipulate it:</div><div><br></div><div><div>apply :: (c a b -> c a2 b2) -> (c b a -> c b2 a2) -> D c a b -> D c a2 b2</div><div>apply f1 f2 (D x y) = D (f1 x) (f2 y)</div></div><div><br></div><div>This is all fine. But I want a shorter function if (f1 = f2). So I write:</div><div><br></div><div>applyBoth f = apply f f<br></div><div><br></div><div>I originally thought that if "apply f f" is valid, then logically "applyBoth f" should also be valid. But it seems that type inference results in applyBoth only working for functions "c a a -> c a2 a2". </div><div><br></div><div>Is there a way to type "applyBoth" so it works for all functions that would work simply by repeating them twice in "apply"?</div></div>