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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:49:30+00:00 2026-06-02T06:49:30+00:00

I was wondering if there is any possibility to implement a logical implication in

  • 0

I was wondering if there is any possibility to implement a logical implication in scala.
For example:

a implies b

translating into:

!a || b

where a and b are some expressions that evaluate to Boolean.

I initially started with following, but that is a wrong approach

  implicit def extendedBoolean(a : Boolean) = new {
    def implies(b : Boolean) = {
      !a || b
    }
  }

since it will evaluate both a and b regardless the value of a. The correct solution would only evaluate b when a is true.

  • 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-06-02T06:49:33+00:00Added an answer on June 2, 2026 at 6:49 am

    You want to use a call-by-name parameter, I believe the following should suffice:

    implicit def extendedBoolean(a : Boolean) = new {
        def implies(b : => Boolean) = {
          !a || b
        }
      }
    

    Explanation:

    You must pass some value in for b but you do not want that expression evaluated; Scala can automatically convert the expression into a function that takes no arguments and evaluates to the expression. Your implies operator then evaluates that nullary (zero-argument) function if need be.

    The compiler knows that it can do this conversion because of the type signature you have provided, => Boolean. This post explains in better detail, but its title alone is a very good nutshell explanation of what is going on: “Automatic Type-Dependent Closure Construction”.

    This feature of Scala enables one to write control constructs, perhaps as easily as one might write them using macros in other languages. Observe how easily they reimplement a while loop using two call-by-name parameters: one for the conditional and one for the body.

    object TargetTest2 extends Application {
      //type signature not too terribly mysterious
      def whileLoop(cond: => Boolean)(body: => Unit): Unit =
        if (cond) {
          body
          whileLoop(cond)(body)
        }
    
      //about as easy to use as a plain-old while() loop
      var i = 10
      whileLoop (i > 0) {
        println(i)
        i -= 1
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wondering if there is any way to get the lambda expressions that result from
I was wondering if there are any sweet languages that offer some sort of
i just wondering is there any performance issue or anything thing wrong if that
Wondering if there is any tool that can help me to detect a pronoun's
I was wondering, is there any possibility to create a table where i have
I'm wondering if there's a possibility to have access to any of developer version
I am wondering is there any mobile phone available in this world that enable
I was wondering is there any tutorial out there that can teach you how
Been wondering are there any ways to measure the learning performance of ANNs. Thanks
I was wondering - are there any known techniques to control access to a

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.