Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8079521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:07:41+00:00 2026-06-05T16:07:41+00:00

I have a problem with protocol-buffers in Haskell. I’m writing a simple UDP receiver

  • 0

I have a problem with protocol-buffers in Haskell. I’m writing a simple UDP receiver and get the error:

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." }

How can I follow it’s advice? (I’m just learning Haskell.)

My Code follows:

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:07:42+00:00Added an answer on June 5, 2026 at 4:07 pm

    From the documentation at http://hackage.haskell.org/packages/archive/protocol-buffers/2.0.9/doc/html/Text-ProtocolBuffers-WireMessage.html#v:messageGet, the type signature of messageGet is

    messageGet :: (ReflectDescriptor msg, Wire msg) => ByteString -> Either String (msg, ByteString)
    

    The return value is either a String error message or a msg and a residual ByteString. In your code, you have written

    case messageGet (B.pack mesg) of
      Left person -> putStrLn $ show person
      Right err   -> error "Failed to parse address book."
    

    If it returns a (msg, ByteString), that value is bound to the variable err. Since err is ignored, the actual type of msg is not determined, which is what the error message is telling you. In fact, any type that’s an instance of Wire and ReflectDescriptor will work, but the program will behave differently for each type! Since the compiler doesn’t know what type you want, you have to specify it. You can specify it by annotating the return type of messageGet.

    case messageGet (B.pack mesg) :: Either String (X, ByteString) of -- Use the actual message type in place of 'X'
      Left person -> putStrLn $ show person
      Right err   -> error "Failed to parse address book."
    

    You probably also meant to switch the Left and Right cases in your code. Right is the non-error case (think “wrong” and “right”). Switching the cases will not get rid of the error message on its own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just come accross Google's Protocol buffers. It seems to be the solution
I have some problem to get the Google Analytics to work. I have got
Actually I'm working on very simple FTP server. Now I have problem with sending
It seems I don't understand something simple about Protocol Buffers, but this is very
I have a problem in HTTP Authentication. I couldn't get the content of this
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with fancybox. I want to write a function that will run
i have problem with autorotate on iphone i set up in all classes -
I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
I have problem with displaying adsense ads in ie7 google adsense adds an iframe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.