import qualified Control
. Monad
data D c a b = D ( c a b) ( c b a)
apply :: ( c a b -> c a2 b2) -> ( c b a -> c b2 a2) -> D c a b -> D c a2 b2
apply f1 f2 ( D x y) = D ( f1 x) ( f2 y)
applyBoth
= Control
. Monad . join apply
h = ( * 2 )
join :: ( a -> b) -> ( c -> d) -> ( ( a, c) -> ( b, d) )
join f g ( x, y) = ( f x, g y)
x1 = D f g
f1 = join h
y1 = apply f1 f1 x1 -- This compiles
y2 = apply g g x1 where g = f1 -- Also works
z1 = applyBoth f1 x1 -- This fails
aW1wb3J0IHF1YWxpZmllZCBDb250cm9sLk1vbmFkCgpkYXRhIEQgYyBhIGIgPSBEIChjIGEgYikgKGMgYiBhKQoKYXBwbHkgOjogKGMgYSBiIC0+IGMgYTIgYjIpIC0+IChjIGIgYSAtPiBjIGIyIGEyKSAtPiBEIGMgYSBiIC0+IEQgYyBhMiBiMgphcHBseSBmMSBmMiAoRCB4IHkpID0gRCAoZjEgeCkgKGYyIHkpCgphcHBseUJvdGggPSBDb250cm9sLk1vbmFkLmpvaW4gYXBwbHkKCmYgOjogSW50IC0+IFN0cmluZwpmID0gc2hvdwoKZyA6OiBTdHJpbmcgLT4gSW50CmcgPSByZWFkCgpoIDo6IEludCAtPiBJbnQKaCA9ICgqMikKCmpvaW4gOjogKGEgLT4gYikgLT4gKGMgLT4gZCkgLT4gKChhLCBjKSAtPiAoYiwgZCkpCmpvaW4gZiBnICh4LCB5KSA9IChmIHgsIGcgeSkKCngxID0gRCBmIGcKCmYxID0gam9pbiBoCgp5MSA9IGFwcGx5IGYxIGYxIHgxIC0tIFRoaXMgY29tcGlsZXMKeTIgPSBhcHBseSBnIGcgeDEgd2hlcmUgZyA9IGYxIC0tIEFsc28gd29ya3MKCnoxID0gYXBwbHlCb3RoIGYxIHgxIC0tIFRoaXMgZmFpbHMKCm1haW4gPSByZXR1cm4gKCkK
compilation info
[1 of 1] Compiling Main ( prog.hs, prog.o )
prog.hs:29:19:
Couldn't match type `[Char]' with `Int'
Expected type: D (->) Int Int
Actual type: D (->) Int String
In the second argument of `applyBoth', namely `x1'
In the expression: applyBoth f1 x1
In an equation for `z1': z1 = applyBoth f1 x1
stdout