我需要創建一個元組列表,每個元組代表一個帶有(x,y,height,width)的矩形。
隨着寬度不變,我需要將高度值加倍。函數應用了三個參數
必要的輸出:
> genRects 3 (0,0)
[(0.0,0.0,5.5,5.5),(5.5,0.0,5.5,5.5),(11.0,0.0,5.5,5.5),(16.5,0.0,5.5,5.5)]
我目前的代碼:
genRects :: Int -> (Int,Int) -> [(Float,Float,Float,Float)]
genRects 0 _ = []
genRects n (x,y) = let height=5.5; width=5.5 in [(fromIntegral x, fromIntegral y, height, width)] genRects (n-1) (x+height, y)
四處錯誤:
Couldn't match expected type `(Int->(Int, Int)-> [(Float, Float, Float, Float)])
-> Int -> (Int, Int) -> [(Float, Float, Float, Float)]'
with actual type `[(Integer, Integer, Double, Double)]'
The function `[(fromIntegral x, fromIntegral y, height, width)]'
is applied to three arguments,
but its type `[(Integer, Integer, Double, Double)]' has none
In the expression:
[(fromIntegral x, fromIntegral y, altura, comp)]
genRects (n - 1) (x + x, y)
In the expression:
let
height= 5.5
width = 5.5
in
[(fromIntegral x, fromIntegral y, height, width)]
genRects (n - 1) (x + x, y)
Failed, modules loaded: none.
而且爲什麼它要翻一番,而不是浮動?