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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:37:30+00:00 2026-05-23T04:37:30+00:00

I want to apply a 3 argument function in different ways based on a

  • 0

I want to apply a 3 argument function in different ways based on a boolean value (one of the arguments).

I’d like to be able to apply it in an infix manner so I can chain it (example below). something like the following but that actually works.

f :: Bool -> a -> a -> a

f True  i j = i
f False i j = j

... y `(f True)` z `(f False)` b

Do I need to have the Bool as the second variable? Or something else? I’m kind of lost.

P.S. the reason I wanted to do this was to have optional append function

  • 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-23T04:37:31+00:00Added an answer on May 23, 2026 at 4:37 am

    The infix notation for functions with more than two arguments is possible but not very nice. In your case, given

    f :: Bool -> a -> a -> a
    f True i j = i
    f False i j = j
    

    you can write

    (True `f` 1) 3
    

    It’s much easier (as suggested by others) to write:

    let ft = f True
    let ff = f False
    

    then you can do

    1 `ft` 3 `ff` 5
    

    If you want to use f you should write:

    (False `f` ((True `f` 1) 3)) 5
    

    You can verify that

    1 `ft` 3 `ff` 5 == (False `f` ((True `f` 1) 3)) 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to apply a function to all columns in a matrix with MATLAB.
I want to apply a function f to a list of values, however function
I want to apply a function to each element of a cell array --
(I made some changes...) very often I want to simplify the function's argument, or
When I want to call a function in javascript with arguments supplied from elsewhere
This should be an easy one. How do I apply a function to a
I want to delegate some function calls from one object to another: objA.feature =
I want a 'curry' like function - this kind of thing function invoker (fn)
I want to be able to pass one object to another, then set up
I'm currently using Function.apply to call a function with a dynamic number of arguments,

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.