मुझे लागू करने वाले फ़ैक्टर और फ़ंक्चर सीखने में मदद करने के लिए मैंने सोचा कि Either
टाइपक्लास Functor
और Applicative
के साथ लागू किया गया है। जाहिर है, मैं बस आगे बढ़ सकता हूं और कोड पढ़ सकता हूं लेकिन चीजों की बेहतर समझ प्राप्त करने के लिए मुझे चीजों को आजमाने और लागू करने के लिए और अधिक उपयोगी लगता है।डेटा को लागू करने का प्रयास कर रहे हैं। या तो
FYI करें मैं इस प्रस्तुति http://applicative-errors-scala.googlecode.com/svn/artifacts/0.6/chunk-html/index.html
वैसे भी के परिणामों की हास्केल संस्करण को लागू करने की कोशिश कर रहा हूँ, यह क्या मैं अब तक
data Validation a b = Success a | Failure b deriving (Show, Eq)
instance Functor (Validation a) where
fmap f (Failure x) = Failure x
fmap f (Success x) = Success (f x)
है लेकिन जब भी मैं ghci
के साथ इस चलाने का प्रयास है मैं सिर्फ निम्न त्रुटि संदेश मिलता है: -
[1 of 1] Compiling Main (t.hs, interpreted)
t.hs:5:35:
Couldn't match type `b' with `a1'
`b' is a rigid type variable bound by
the type signature for
fmap :: (a1 -> b) -> Validation a a1 -> Validation a b
at t.hs:4:5
`a1' is a rigid type variable bound by
the type signature for
fmap :: (a1 -> b) -> Validation a a1 -> Validation a b
at t.hs:4:5
Expected type: a
Actual type: b
In the return type of a call of `f'
In the first argument of `Success', namely `(f x)'
In the expression: Success (f x)
t.hs:5:37:
Couldn't match type `a' with `a1'
`a' is a rigid type variable bound by
the instance declaration at t.hs:3:30
`a1' is a rigid type variable bound by
the type signature for
fmap :: (a1 -> b) -> Validation a a1 -> Validation a b
at t.hs:4:5
In the first argument of `f', namely `x'
In the first argument of `Success', namely `(f x)'
In the expression: Success
मैं सच में यकीन है कि ऐसा क्यों है नहीं कर रहा हूँ, किसी को भी मदद कर सकते हैं?
आह मैं देख रहा हूँ, धन्यवाद, मैं 'मानते हुए कर रहा हूँ डेटा मान्यकरण एक ख = विफलता एक | सफलता बी प्राप्त करना (दिखाएँ, ईक) 'भी सही होगा। धन्यवाद! – djhworld
@ डीजेवर्ल्ड: हाँ। टाइप वैरिएबल के नाम और कन्स्ट्रक्टर के ऑर्डर के साथ यह वही बात है। – hammar
@djhworld: और अब आप यह भी समझते हैं कि, 'या तो एक बी' में, 'वाम' विफलता के मामले का प्रतिनिधित्व करता है (न सिर्फ इसलिए कि यह "सही" परिणाम नहीं है)। –