मैं है निम्नलिखित हास्केल कोड:उम्मीद मिलान नहीं हो पाया प्रकार `इंट 'वास्तविक प्रकार के साथ` पूर्णांक'
-- Problem 69
import ProjectEuler
phi :: Integer -> Integer
phi n = n * product [p - 1 | p <- primeDivisors n] `div` product [p | p <- primeDivisors n]
-- primeDivisors n is a list of the prime divisors of n
maxRatio :: (Int, Int, Double) -> (Int, Int, Double) -> (Int, Int, Double)
maxRatio [email protected](_, _, x) [email protected](_, _, y)
| x > y = t1
| otherwise = t2
main = print (foldl
maxRatio
(0, 0, 0.0)
[(n, phi n, ratio) | n <- [2..max], let ratio = fromIntegral n/(fromIntegral (phi n))]
)
where max = 1000
जो निम्न त्रुटि देता है:
Couldn't match expected type `Int' with actual type `Integer'
In the expression: n
In the expression: (n, phi n, ratio)
In the third argument of `foldl', namely
`[(n, phi n, ratio) |
n <- [2 .. max],
let ratio = fromIntegral n/(fromIntegral (phi n))]'
मैं में संदेह है कि ट्रिपल (0, 0, 0.0)
0 के Int
हैं। 0
हमेशा Int
टाइप करें या इस मामले में ghci Int
के रूप में इस प्रकार को कम कर रहा है? यदि बाद में, मैं इसे Integer
टाइप करने के लिए कैसे मजबूर करूं? या क्या कोई और चीज है जो इस त्रुटि का कारण बनती है?
स्पष्ट स्पष्टीकरण के लिए धन्यवाद। मैंने सोचा कि '0' इसके प्रकार में पॉलिमॉर्फिक था, लेकिन मेरी नोब आंखों को प्रकार के अनुमान के लिए कोई अन्य कारण नहीं दिख रहा था जिससे त्रुटि मिली। बेशक, मैंने बस 'maxRatio' के लिए मेरी स्पष्ट प्रकार की घोषणा को याद किया। –