Haskell: composing function with two floating arguments fails -
i trying compose function of type (floating a) => -> -> a function of type (floating a) => -> a obtain function of type (floating a) => -> -> a. have following code:
test1 :: (floating a) => -> -> test1 x y = x test2 :: (floating a) => -> test2 x = x testboth :: (floating a) => -> -> testboth = test2 . test1 --testboth x y = test2 (test1 x y) however, when compile in ghci, following error:
/path/test.hs:8:11: not deduce (floating (a -> a)) context (floating a) arising use of `test2' @ /path/test.hs:8:11-15 possible fix: add (floating (a -> a)) context of type signature `testboth' or add instance declaration (floating (a -> a)) in first argument of `(.)', namely `test2' in expression: test2 . test1 in definition of `testboth': testboth = test2 . test1 failed, modules loaded: none. note commented-out version of testboth compiles. strange thing if remove (floating a) constraints type signatures or if change test1 take x instead of x , y, testboth compiles.
i've searched stackoverflow, haskell wikis, google, etc. , not found restriction on function composition relevant particular situation. know why happening?
\x y -> test2 (test1 x y) == \x y -> test2 ((test1 x) y) == \x y -> (test2 . (test1 x)) y == \x -> test2 . (test1 x) == \x -> (test2 .) (test1 x) == \x -> ((test2 .) . test1) x == (test2 .) . test1 these 2 things not each other.
test2 . test1 == \x -> (test2 . test1) x == \x -> test2 (test1 x) == \x y -> (test2 (test1 x)) y == \x y -> test2 (test1 x) y
Comments
Post a Comment