2015-08-27 17 views
6

İki modül yazdım. İlki DhtTypes denir:Yüklü modülden işlev yok

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 

ikincisi MessageTypes geçerli:

Ben GHCi içinde MessageTypes yüklediğinizde Bu ne oldu edilir
module MessageTypes() where 

-- import stuff 

import DhtTypes 

data PingR = PingR TransactionID Hash20Bytes 

-- stuff 

:

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> 

Zaten ghci not loading function from file okudum ve Beginning Haskell - getting “not in scope: data constructor” error, ama yine de bir cevap bulamadım.

cevap

8

Hash20Bytes türünü dışa aktarıyorsunuz, ancak kurucuyu Hash20Bytes dışa aktarmıyorsunuz. Çok bu

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

(..) gibi yapabileceği bir türü/typeclass tüm kurucular/üyelerini ihraç ediyor. Yalnızca belirli olanları dışa aktarmak istiyorsanız, virgülle ayrılmış bir ad listesi belirtebilirsiniz, ancak genellikle (..) deneyimimin en iyisidir.

İlgili konular