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 6671725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:25:23+00:00 2026-05-26T03:25:23+00:00

Trying to convert a bytestring to a hex ascii string display wordtoascii :: Int

  • 0

Trying to convert a bytestring to a hex ascii string display

wordtoascii :: Int -> String
wordtoascii y =
  showIntAtBase 16 intToDigit ( fromEnum  y) ""

bs2string :: Data.ByteString.ByteString -> String
bs2string bs = do
  Prelude.map( wordtoascii,
               (unpack bs))

Type error:

Couldn't match expected type `a -> b'
       against inferred type `(Int -> String, [GHC.Word.Word8])'
In the first argument of `Prelude.map', namely
    `(wordtoascii, (unpack bs))'
In the expression: Prelude.map (wordtoascii, (unpack bs))
In the expression: do { Prelude.map (wordtoascii, (unpack bs)) }
  • 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-05-26T03:25:23+00:00Added an answer on May 26, 2026 at 3:25 am

    This is not the syntax for what you think it is.

    Prelude.map( wordtoascii,
                (unpack bs))
    

    That is the same as:

    let x = (wordtoascii, unpack bs)
    in map x
    

    Remove the parentheses and the comma.

    map wordtoascii (unpack bs)
    

    However, this is also wrong. Because the type of the above expression is [String], not String. You want concatMap, which is like map but splices the results together in one string.

    concatMap wordtoascii (unpack bs)
    

    Or, even better,

    bs2string = concatMap wordtoascii . unpack
    

    The comma is for creating tuples, lists, and records. For example, (1, 7) :: (Int, Int) could be cartesian coordinates. The comma does not appear in function calls.

    Typically, ByteString is imported only as a qualified import, since so many functions clash with Prelude. This eliminates the need for Prelude. qualification on the functions that do clash.

    import qualified Data.ByteString as S
    bs2string = map wordtoascii . S.unpack
    

    The S stands for Strict. BS is also a common choice, it stands for for Bytestring (Strict).

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

Sidebar

Related Questions

I'm trying convert jQuery Data object to JSON string. I tried: $.data(plant).toJSON() JSON.stringify($.data(plant)) but
Trying to convert int arrays to string arrays in numpy In [66]: a=array([0,33,4444522]) In
Trying to convert this c code into MIPS and run it in SPIM. int
I am trying to convert an int into three bytes representing that int (big
I always run into the following error when trying to read a ByteString: Prelude.read:
I'm trying to convert a big-endian 2 byte string into a numeric port number.
am trying convert string to float,when i am passing single char it is giving
How to extract and save array from string parameter? I'm trying convert string beafore_create
Trying to convert a string to NSURL and this is not happening. barcodeTextLabel.text =
im trying to convert a json object to a string by using gson here

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.