2015-08-27 12 views
6

मैंने दो मॉड्यूल लिखे हैं। पहले एक DhtTypes कहा जाता है:लोड मॉड्यूल से फ़ंक्शन स्कोप में नहीं

module DhtTypes (Bencode, encode, TransactionID, Hash20Bytes) where 

-- import stuff 

class Bencode a where 
    encode :: a -> ByteString.ByteString 

data TransactionID = TransactionID Int.Int16 
data Hash20Bytes = Hash20Bytes [Word.Word8] 

-- stuff 

दूसरा एक MessageTypes है:

module MessageTypes() where 

-- import stuff 

import DhtTypes 

data PingR = PingR TransactionID Hash20Bytes 

-- stuff 

यह क्या हो रहा है जब मैं GHCi में MessageTypes लोड:

GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help 
Loading package ghc-prim ... linking ... done. 
Loading package integer-gmp ... linking ... done. 
Loading package base ... linking ... done. 
[1 of 2] Compiling DhtTypes   (DhtTypes.hs, interpreted) 
[2 of 2] Compiling MessageTypes  (/home/{path}/MessageTypes.hs, interpreted) 
Ok, modules loaded: MessageTypes, DhtTypes. 
*MessageTypes> :browse DhtTypes 
class Bencode a where 
    encode :: a -> ByteString.ByteString 
data TransactionID = DhtTypes.TransactionID GHC.Int.Int16 
data Hash20Bytes = DhtTypes.Hash20Bytes [GHC.Word.Word8] 
*MessageTypes> Hash20Bytes 

<interactive>:3:1: Not in scope: data constructor `Hash20Bytes' 
*MessageTypes> :l DhtTypes 
[1 of 1] Compiling DhtTypes   (DhtTypes.hs, interpreted) 
Ok, modules loaded: DhtTypes. 
*DhtTypes> Hash20Bytes [0..10] 
Loading package array-0.4.0.1 ... linking ... done. 
Loading package deepseq-1.3.0.1 ... linking ... done. 
Loading package bytestring-0.10.0.2 ... linking ... done. 
Loading package bytestring-builder-0.10.6.0.0 ... linking ... done. 
a 
*DhtTypes> 

मैं पहले से ही ghci not loading function from file पढ़ लिया है और Beginning Haskell - getting “not in scope: data constructor” error, लेकिन मुझे अभी भी कोई जवाब नहीं मिला।

उत्तर

8

आप Hash20Bytes टाइप कर रहे हैं, लेकिन आप निर्माता Hash20Bytes निर्यात नहीं कर रहे हैं। तुम इतनी तरह इस

module DhtTypes 
    (Bencode(..) 
    , TransactionID(..) 
    , Hash20Bytes(..) 
    ) where 

(..) कर सकते हैं एक प्रकार/typeclass के सभी निर्माताओं/सदस्यों निर्यात करता है। यदि आप केवल विशिष्ट निर्यात करना चाहते हैं, तो आप नामों की अल्पविराम से अलग सूची निर्दिष्ट कर सकते हैं, लेकिन आमतौर पर (..) मेरे अनुभव में सबसे अच्छा है।

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