मैं स्वीकार्य रूप से एक हास्केल नौसिखिया हूँ। (दशमलव के रूप में व्यक्त)एक साधारण हास्केल फ़ंक्शन अनुपात के रूप में व्यक्त किए गए फ्रैक्शनल तर्क को अस्वीकार क्यों करता है?
Prelude> let latter x y = y
latter :: t -> t1 -> t1
मैं प्रकार Char
, [Char]
, Num
, Floating
के तर्कों से कॉल करने में सक्षम हूँ, और Fractional
: आलस्य का पता लगाने के लिए, मैं GHCi में एक समारोह है कि इसके दूसरे तर्क देता है बनाया
Prelude> latter 'x' 'y'
'y'
it :: Char
Prelude> latter "foo" "bar"
"bar"
it :: [Char]
Prelude> latter 1 2
2
it :: Num t1 => t1
Prelude> latter pi pi
3.141592653589793
it :: Floating t1 => t1
Prelude> latter 0.5 0.7
0.7
it :: Fractional t1 => t1
मैं एक भयानक त्रुटि क्यों मिलता है (और इसका क्या मतलब है) के लिए एक Fractional
एक अनुपात के रूप में व्यक्त जब मैं latter
लागू करने का प्रयास करें:
Prelude> 1/2
0.5
it :: Fractional a => a
Prelude> latter 1/2 1/2
<interactive>:62:1:
Could not deduce (Num (a0 -> t1 -> t1))
arising from the ambiguity check for ‘it’
from the context (Num (a -> t1 -> t1),
Num a,
Fractional (t1 -> t1))
bound by the inferred type for ‘it’:
(Num (a -> t1 -> t1), Num a, Fractional (t1 -> t1)) => t1 -> t1
at <interactive>:62:1-14
The type variable ‘a0’ is ambiguous
When checking that ‘it’
has the inferred type ‘forall t1 a.
(Num (a -> t1 -> t1), Num a, Fractional (t1 -> t1)) =>
t1 -> t1’
Probable cause: the inferred type is ambiguous
आपको माता-पिता की आवश्यकता है: 'बाद वाला (1/2) (1/2) '। – Jubobs
डी ओह! धन्यवाद। –