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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:19:48+00:00 2026-05-11T01:19:48+00:00

When I have some function of type like f :: (Ord a) => a

  • 0

When I have some function of type like

f :: (Ord a) => a -> a -> Bool f a b = a > b 

I should like make function which wrap this function with not.

e.g. make function like this

g :: (Ord a) => a -> a -> Bool g a b = not $ f a b 

I can make combinator like

n f = (\a -> \b -> not $ f a b) 

But I don’t know how.

*Main> let n f = (\a -> \b -> not $ f a b) n :: (t -> t1 -> Bool) -> t -> t1 -> Bool Main> :t n f n f :: (Ord t) => t -> t -> Bool *Main> let g = n f g :: () -> () -> Bool 

What am I doing wrong?

And bonus question how I can do this for function with more and lest parameters e.g.

t -> Bool t -> t1 -> Bool t -> t1 -> t2 -> Bool t -> t1 -> t2 -> t3 -> Bool 
  • 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. 2026-05-11T01:19:48+00:00Added an answer on May 11, 2026 at 1:19 am

    Unless you want to go hacking around with typeclasses, which is better left for thought experiments and proof of concept, you just don’t generalize to multiple arguments. Don’t try.

    As for your main question, this is most elegantly solved with Conal Elliott’s semantic editor combinators. A semantic editor combinator is a function with a type like:

    (a -> b) -> F(a) -> F(b) 

    Where F(x) is some expression involving x. There are also ‘contravariant’ editor combinators which take a (b -> a) instead. Intuitively, an editor combinator selects a part of some larger value to operate on. The one you need is called result:

    result = (.) 

    Look at the type of the expression you’re trying to operate on:

    a -> a -> Bool 

    The result (codomain) of this type is a -> Bool, and the result of that type is Bool, and that’s what you’re trying to apply not to. So to apply not to the result of the result of a function f, you write:

    (result.result) not f 

    This beautifully generalizes. Here are a few more combinators:

    argument = flip (.)     -- contravariant  first f (a,b) = (f a, b) second f (a,b) = (a, f b)  left f (Left x) = Left (f x) left f (Right x) = Right x ... 

    So if you have a value x of type:

    Int -> Either (String -> (Int, Bool)) [Int] 

    And you want to apply not to the Bool, you just spell out the path to get there:

    (result.left.result.second) not x 

    Oh, and if you’ve gotten to Functors yet, you’ll notice that fmap is an editor combinator. In fact, the above can be spelled:

    (fmap.left.fmap.fmap) not x 

    But I think it’s clearer to use the expanded names.

    Enjoy.

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

Sidebar

Related Questions

I have some jquery that looks like this, $('.career_select .selectitems').click(function(){ var selectedCareer = $(this).attr('title');
I have some code, which was written couple of years ago and works only
I have a script which is posting some form data to a Quickbase and
In C# it is not possible to override a static method. Nevertheless I have
Say you have some target class with some methods on it: class Subject {
I have jQuery UI dialog with ASP.NET. I wrap a list of check boxes
I am wondering about the benefits of having the string-type immutable from the programmers
I'm working on making my first Python C extension, which defines a few functions
I'm using Fancybox ( http://fancybox.net ) to pop open an iFrame. In order to
When using Enums with bit fields: enum ReallyBigEnum { FirstChoice = 0x01, AnotherOption =

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.