하스켈의 protocol-buffers에 문제가 있습니다. 간단한 UDP 수신자를 작성하고 오류가 발생합니다 :"ambiguous type 변수`msg0 '을 제약 조건에서 제거하는 방법"
src/Main.hs:39:25:
Ambiguous type variable `msg0' in the constraints:
(Wire msg0)
arising from a use of `messageGet' at src/Main.hs:39:25-34
(Text.ProtocolBuffers.Reflections.ReflectDescriptor msg0)
arising from a use of `messageGet' at src/Main.hs:39:25-34
Probable fix: add a type signature that fixes these type variable(s)
In the expression: (messageGet (B.pack mesg))
In the second argument of `($)', namely
`case (messageGet (B.pack mesg)) of {
Left person -> putStrLn $ show person
Right err -> error $ "Failed to parse address book." }'
In a stmt of a 'do' block:
return
$ case (messageGet (B.pack mesg)) of {
Left person -> putStrLn $ show person
Right err -> error $ "Failed to parse address book." }
어떻게하면 되나요? (. 난 그냥 하스켈을 배우고)
는내 코드는 다음과 같습니다
module Main where
import Data.Bits
import Network.Socket -- hiding (send, sendTo, recv, recvFrom)
-- import Network.Socket.ByteString
import Network.BSD
import Data.List
import qualified Data.ByteString.Lazy.Char8 as B
import Text.ProtocolBuffers.Header (defaultValue, uFromString)
import Text.ProtocolBuffers.WireMessage (messageGet, messagePut, Wire)
import Data.Sequence ((><), fromList)
import AddressBookProtos.AddressBook
import AddressBookProtos.Person
import AddressBookProtos.Person.PhoneNumber
import AddressBookProtos.Person.PhoneType
import Network.Socket
import System.Posix.Directory
import System.Posix.Files
import System.Posix.IO
import System.Posix.Process
import System.Exit
echoserver :: IO()
echoserver = do
withSocketsDo $ do
sock <- socket AF_INET Datagram 0
bindSocket sock (SockAddrInet 4567 iNADDR_ANY)
socketRx sock
socketRx :: Socket -> IO()
socketRx sock = do
(mesg, recv_count, client) <- recvFrom sock 1500
return $ case (messageGet (B.pack mesg)) of
Left person -> putStrLn $ show person
Right err -> error $ "Failed to parse address book."
socketRx sock
main::IO()
main = echoserver
고마워요.하지만 X가 무엇인지 알아 내려고 노력하고 있습니다. 필자는 'Wire'(Wire에 대한 또 다른 주장이 필요함)와 'Wire Person'(유형으로 사용되는 Predicate Wire Person)을 시도했습니다. – fadedbee
X = Person을 시도해 봤습니다. 답변을 주셔서 감사합니다. – fadedbee