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

  • Home
  • SEARCH
  • 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 8755485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:52:10+00:00 2026-06-13T13:52:10+00:00

import Data.ByteString as B import Data.ByteString.Internal as I import Data.Bits main = do input

  • 0
import Data.ByteString as B
import Data.ByteString.Internal as I
import Data.Bits
main = do input <- getLine
      let bs = B.pack input
      let intermediatebs  =  unfoldrN ((B.length bs)*2) unfld 0
      where unfld i
      |Prelude.rem i 2 == 0 = Just (top4 $ B.index bs (i/2) , i+1)
      |otherwise =  Just (bottom4 $ B.index bs (i/2) , i+1)
      top4bits x = shiftR x 4
      bottom4bits x = x .&. 0x0F
      top4 x = convertASCIIword8 $ top4bits x
      bottom4 x = convertASCIIword8 $ bottom4bits x
      convertASCIIword8 x
      |x <= 9 = I.c2w '0' + x
      |otherwise = I.c2w 'A' + (x-10)
      let outputbs = B.map I.w2c $ intermediatebs
      in do putStrLn (outputbs)

i am getting this compilation error
The last statement in a ‘do’ construct must be an expression:
let intermediatebs = unfoldrN ((B.length bs) * 2) unfld 0

  • 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-13T13:52:11+00:00Added an answer on June 13, 2026 at 1:52 pm

    It’s hard to see exactly what you want here. It is possible to make your code parse with only indentation changes:

    import Data.ByteString as B
    import Data.ByteString.Internal as I
    import Data.Bits
    main = do
      input <- getLine
      let bs = B.pack input
      let intermediatebs  =  unfoldrN ((B.length bs)*2) unfld 0
           where
            unfld i
              | Prelude.rem i 2 == 0 = Just (top4 $ B.index bs (i/2) , i+1)
              | otherwise =  Just (bottom4 $ B.index bs (i/2) , i+1)
            top4bits x = shiftR x 4
            bottom4bits x = x .&. 0x0F
            top4 x = convertASCIIword8 $ top4bits x
            bottom4 x = convertASCIIword8 $ bottom4bits x
            convertASCIIword8 x
              | x <= 9 = I.c2w '0' + x
              | otherwise = I.c2w 'A' + (x-10)
      let outputbs = B.map I.w2c $ intermediatebs
      putStrLn (outputbs)
    

    although it won’t compile due to ambiguous getLine and putStrLn occurrences. You may want to import qualified where appropriate. Key observations:

    • Do-blocks, let-blocks etc. start from the left edge of the first thing inside them, regardless of where the keyword is itself. E.g.

      do x
         y
      -- ^ because of where the x is, all future lines have to line up with it
      
      let x = ...
          y = ...
      -- ^ if you have code appearing left of here, the let-block ends
      

      As a consequence, I often give do and where their own line before starting a block. In the example I gave above, you can see that even if I moved the do-block into a function with a longer or shorter name, the indentation wouldn’t change.

    • Lines in the same block that start indented are a continuation of the previous line. Guards are a continuation so need to be indented, likewise where for a let assignment needs to be indented further than the assignment itself.

    • The in do at the end of your block was redundant, so I removed it (alternatively, just indenting it would have worked too).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the file-embed package thusly: import qualified Data.ByteString as B import qualified Data.ByteString.Internal
import System.Directory import qualified Data.ByteString as BS import qualified Data.ByteString.UTF8 as BS_UTF8 main =
I'm trying to parse a binary format (PES) using Haskell: import qualified Data.ByteString.Lazy as
Suppose I have: import qualified Data.ByteString.Lazy as L bs1 :: L.ByteString bs2 :: L.ByteString
I want to split ByteString to words like so: import qualified Data.ByteString as BS
I have the following test application: import Codec.Crypto.AES import qualified Data.ByteString.Char8 as B key
I've got the following code: import Data.Binary.Get import qualified Data.ByteString.Lazy as L import qualified
I have the following snippet: import qualified Data.Vector as V import qualified Data.ByteString.Lazy as
I import data from a TSV file with SQL Server 2008. null is replaced
I have to import data from an Excel file to database and to do

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.