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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:00:45+00:00 2026-05-13T06:00:45+00:00

I recently came across this problem and found a solution but I’m wondering if

  • 0

I recently came across this problem and found a solution but I’m wondering if there are better (or just more idiomatic) solutions.

I have a structure for a colour:

data Rgb = Rgb Double Double Double

And there is a function I’d like to pass the colour components to individually, actually from Cairo:

setSourceRGB :: Double -> Double -> Double -> Render ()

So I need to “unpack” this data structure somehow, since setSourceRGB doesn’t take an Rgb. I found two ways. One is to define a function to apply the contents of an Rgb:

applyRgb :: (Double -> Double -> Double -> t) -> Rgb -> t
applyRgb f (Rgb r g b) = f r g b

Then I can do:

applyRgb setSourceRGB rgb

Another way I came up with is to do an inline lambda expression with a case, which means I don’t have to define a separate function:

(\z -> (case z of (Rgb r g b) -> setSourceRGB r g b)) rgb

I’m not completely happy with this however, somehow applying a function just to pass some values doesn’t seem right. I’d like to be able to turn it around, and “convert” the Rgb to the right type for setSourceRGB. Unfortunately it seems to me that’s it’s impossible to have a function

fromRgb :: Rgb -> Double -> Double -> Double

that can be passed to setSourceRGB. Perhaps applyRgb is the best solution, but I’m wondering if there’s some better way that will let me express it as:

setSourceRGB (fromRgb rgb)
  • 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-13T06:00:46+00:00Added an answer on May 13, 2026 at 6:00 am

    No, you can’t write something like setSourceRGB (fromRgb rgb), because it will just give one argument to the function, so applyRgb seems like the best solution.
    If you like this sort of thing, you can also use applyRgb as an infix function :

    setSource `applyRgb` rgb
    

    If you often use this function, your can make your code easier to read by defining a name for applyRgb setSource.

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

Sidebar

Related Questions

I recently came across http://chromeexperiments.com/ . I found a couple of projects there that
recently I came across this term,but really have no idea what it refers to.I've
Came across this curiosity recently. One solution, with two projects within it (ORM and
I recently came across this in some code - basically someone trying to create
I came across this recently, up until now I have been happily overriding the
Recently I was trying some practice programs in python and I came across this
I recently came across a big problem, as I have a system that's paying
I'm working with strings in C++. I recently came across a problem when entering
I recently came across a problem with My.Computer.FileSystem.DeleteDirectory() . It will not delete read
I am pretty new to C. I recently came across this piece of code

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.