2015-05-26 22 views
6

मैं एक शीर्षलेख फ़ाइल में कोई फ़ंक्शन निर्दिष्ट करने का प्रयास कर रहा हूं। तो जैसा:एरलांग हेडर फ़ाइल में उसी फ़ंक्शन के लिए एकाधिक विनिर्देश

-spec update(pid(), tuple(tuple(), integer(), atom()), tuple(atom(), atom())) -> tuple(tuple(), integer(), atom()). 

अब मैं इस समारोह के लिए कुछ अतिरिक्त विनिर्देश जोड़ना चाहते हैं, क्योंकि यह कई विभिन्न मापदंडों है।

update(_Pid, {Specs, infinity, _State}, {Step}) -> 
    timer:sleep(10000), 
    {{Specs, infinity}, {Step}}; 
update(_Pid, {Specs, infinity, _State}, {ExtraInfo, Step}) -> 
    timer:sleep(10000), 
    {{Specs, infinity}, {ExtraInfo, Step}}; 
update(_Pid, {Specs, N, _State}, _Info) when N < 2 -> 
    {Specs, N, stop}; 
update(_Pid, {Specs, N, _State}, {notTaken, Step}) -> 
    {Specs, N, Step}; 
update(_Pid, {Specs, N, _State}, {taken, Step}) -> 
    {Specs, N - 1, Step}. 

तो मैं अपने शीर्षलेख फ़ाइल में, इस फ़ंक्शन के विभिन्न पैरामीटर के लिए, इन अतिरिक्त विनिर्देशों को जोड़ना चाहता हूं। मुझे नहीं पता कि यह कैसे करना है, क्या कोई मेरी मदद कर सकता है?

मैं यह करने की कोशिश की लेकिन यह मेरे संकलन त्रुटियों देता है:

-spec update(pid(), tuple(tuple(), integer(), atom()), tuple(atom(), atom())) -> tuple(tuple(), integer(), atom()). 
-spec update(pid(), tuple(tuple(), atom(), atom()), tuple(integer(), atom())) -> tuple(tuple(), atom(), atom()). 
-spec update(pid(), tuple(tuple(), atom(), atom()), tuple(atom())) -> tuple(tuple(), atom(), atom()). 

अग्रिम धन्यवाद।

उत्तर

2

मिले जवाब यहाँ: http://erlang.org/doc/reference_manual/typespec.html

मैं का इस्तेमाल किया था ';'

परिवर्तन इस:

-spec update(pid(), tuple(tuple(), integer(), atom()), tuple(atom(), atom())) -> tuple(tuple(), integer(), atom()). 
-spec update(pid(), tuple(tuple(), atom(), atom()), tuple(integer(), atom())) -> tuple(tuple(), atom(), atom()). 
-spec update(pid(), tuple(tuple(), atom(), atom()), tuple(atom())) -> tuple(tuple(), atom(), atom()). 
इस में

:

-spec update(pid(), tuple(tuple(), integer(), atom()), tuple(atom(), atom())) -> tuple(tuple(), integer(), atom()); 
      (pid(), tuple(tuple(), atom(), atom()), tuple(integer(), atom())) -> tuple(tuple(), atom(), atom()); 
      (pid(), tuple(tuple(), atom(), atom()), tuple(atom())) -> tuple(tuple(), atom(), atom()). 
+0

यह सही है। क्या मैं पूछ सकता हूं कि आप इसे हेडर फ़ाइल में क्यों रखना चाहते हैं? –

+0

अपना कोड मजबूत बनाने के लिए और इसमें कार्यक्षमता है जिसे डुप्लिकेट किया जा सकता है। –

+1

क्या आपने व्यवहार के साथ -कॉलबैक तंत्र का उपयोग करने पर विचार किया है? वे आपको कई स्थानों पर दोहराने के बजाय व्यवहार परिभाषा पर टाइप विनिर्देश डाल देते हैं। –

संबंधित मुद्दे