haskell - And another one type error -


sumofsquare :: int -> int -> int sumofsquare b = * + b * b  hipotenuse :: int -> int -> int hipotenuse b = truncate(sqrt(x))            x = fromintegral(sumofsquare b)  squarecheck :: int -> bool squarecheck n = truncate(sqrt(x)) * truncate(sqrt(x)) == n          x = fromintegral n  isitsquare :: int -> int -> bool isitsquare b = squarecheck (sumofsquare b)  calc :: (integral a) => -> [(a, a, a)] calc = [(x, y, (hipotenuse x y)) | x <- [1..a], y <-[1..a], (isitsquare x y)] 

error message:

prelude> :load "some.hs" [1 of 1] compiling main             ( some.hs, interpreted )  some.hs:16:74:     couldn't match expected type `int' against inferred type `a'       `a' rigid type variable bound           type signature `calc' @ some.hs:15:18     in first argument of `isitsquare', namely `x'     in expression: (isitsquare x y)     in stmt of list comprehension: (isitsquare x y) failed, modules loaded: none. 

as understand type of 'x' , 'y'. right? square require int. type 'x' , 'y'? thinked int.

your type general. passing x , y isitsquare, expecing ints, don't know x , y ints. be, other instance of integral well. either change signature more specific:

calc :: int -> [(int, int, int)] 

or have helper functions work on more general types:

squarecheck :: (integral a) => -> bool ... 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -