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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:27:06+00:00 2026-05-25T01:27:06+00:00

loadTexture :: String -> IO (Either String GL.GLuint) loadTexture filename = do p <-

  • 0
loadTexture :: String -> IO (Either String GL.GLuint)
loadTexture filename = do
    p <- PNG.loadPNGFile filename
    oglLoadImg p
    where
        oglLoadImg :: (Either String PNG.PNGImage) -> IO (Either String GL.GLuint)
        oglLoadImg (Left e) = return $ Left e 
        oglLoadImg (Right png) = do
            ... I need todo IO stuff in here

The code above seems really bloated and nasty. What can I do to make it simpler?

  • 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-25T01:27:07+00:00Added an answer on May 25, 2026 at 1:27 am

    You essentially want a combination of the Either e monad and the IO monad. That’s what monad transformers are for!

    In this case, you can use the ErrorT monad transformer which adds error handling using Either to an underlying monad, in this case IO.

    import Control.Monad.Error
    
    loadTexture :: String -> IO (Either String GL.GLuint)
    loadTexture filename = runErrorT $ ErrorT (PNG.loadPNGFile filename) >>= oglLoadImg
        where
            oglLoadImg :: PNG.PNGImage -> ErrorT String IO GL.GLuint
            oglLoadImg png = do
                -- [...]
    

    This keeps the old interface, although it would probably be even nicer to use ErrorT for your function as well, and have the call to runErrorT in your main function.

    loadTexture :: String -> ErrorT String IO GL.GLuint
    loadTexture filename = ErrorT (PNG.loadPNGFile filename) >>= oglLoadImg
        where
            oglLoadImg :: PNG.PNGImage -> ErrorT String IO GL.GLuint
            oglLoadImg png = do
                -- [...]
    

    Monad transformers can take some getting used to, but they are very useful.

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

Sidebar

Related Questions

In my situation, glutInitWindowSize(w_walker*8, h_walker); glutCreateWindow(walker); loadTexture(./fighter512.png); worked, but loadTexture(./fighter512.png); glutInitWindowSize(w_walker*8, h_walker); glutCreateWindow(walker); did
I'm trying to initialize a private variable of my Class passing a const string
I need Vecmath, so I went to Oracle to get the latest version of
Currently ive got some reference counted classes using the following: class RefCounted { public:
All, I am trying to load up a bmp file into a GLubyte array
I am beginning to work on my first OpenGL iPhone app, but I've hit
I have a c++ app that I'm trying to port to iPhone and to
I'm writting a 2d game in Iphone, which uses textures as sprites, I'm getting
I am trying to do some Image processing on a UIImage using some EAGLView
I'm programming a small app with opengl for the iphone, and now I want

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.