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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:24:03+00:00 2026-05-27T17:24:03+00:00

When I try and read a plaintext file from within my Haskell program I

  • 0

When I try and read a plaintext file from within my Haskell program I get:

[fromList * Exception: /path/to/file/aaa.txt hGetContents: invalid argument (Invalid or incomplete multibyte or wide character)

I googled to find this problem is usually set right by setting LANG to en_US.UTF-8
That’s already how my locale looks.

Not sure if this is an issue with GHC at all.

I am on Ubuntu 11.10

  • 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-27T17:24:03+00:00Added an answer on May 27, 2026 at 5:24 pm

    Are you sure aaa.txt contains valid UTF-8? If it’s binary data, you need to use withBinaryFile or similar. If it is text in another encoding, you should use hSetEncoding.

    For instance, if your text is in Latin-1 then you would say

    hSetEncoding h latin1
    

    where “h” is your file handle. If you are reading from standard input then its

    hSetEncoding stdin latin1
    

    There is also a mkTextEncoding function which you can use if you have read the encoding from metadata, or wish to customise the handling of invalid Unicode (although this only works on some systems).

    The Unicode standards say that a Unicode parser should reject invalid strings with an error, rather than trying to fix them up. This is a deliberate rejection of Postel’s Law, on the grounds of reducing security holes and inconsistent interpretations.

    (You might want to consider using the text library if you’ll be working with a lot of text and having to handle encoding issues; it’s usually a lot faster than using Strings, since it uses an unboxed array rather than a linked list, although this means that Text values and operations on them are necessarily strict. It also lets you configure how to respond to invalid Unicode more portably and flexibly.)

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

Sidebar

Related Questions

I try to read file /proc/'pid'/status, using c program. The code is as follows,
I get a warning in MSVC++ when I try to read an integer from
Did anyone try to read programmatically an Alibre Design CAD file? I see that
When I try to read bash history into vim, I get nothing. :r !history
fopen is failing when I try to read in a very moderately sized file
I have a very big file 4GB and when I try to read it
In the following code, I try to read data from a plist: -(void)readPreferences {
I try to read and write data from/to Socket with NSStream. Here is my
I try to read JSON file with Java. The code is: public static void
When i am try to read from SslStream function Read() is never end if

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.