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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:48:44+00:00 2026-05-25T00:48:44+00:00

This works def func(f: => Int) = f This dosn’t (inside class for example)

  • 0

This works

def func(f: => Int) = f

This dosn’t (inside class for example)

type EmptyFunct = => Int

or

 type EmptyFunct = (=> Int)

Scala version 2.9
Two questions:

  1. Why dosn’t syntax sugar work in second case?
  2. How to define this function without syntax sugar?
  • 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-25T00:48:44+00:00Added an answer on May 25, 2026 at 12:48 am

    => Int is not exactly a function without parameter, it is an Int argument with call by name passing convention. (Of course, that is rather fine a point, as it is implemented by passing a function without parameter ).

    The function without argument is written () => Int. You can do type EmptyFunct = () => Int.

    It is not a type. Inside func, f will be typed as an Int. An argument of type () => Int will not.

    def func(f: => Int) = f *2
    

    func (: => Int) Int

    But

    def func(f: () => Int) : Int = f*2
    

    error: value * is not a member of () => Int

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

Sidebar

Related Questions

This works: class ButtonCountObserver { private var cnt = 0 // private field def
Consider the following Scala code: package scala_java object MyScala { def setFunc(func: Int =>
Unless I'm mistaken, creating a function in Python works like this: def my_func(param1, param2):
How can I make this code work? class Meta @array = [:a,:b] def self.method_missing(name,
Anyone know how to get this to work if it's possible? class Foo def
This works (prints, for example, 3 arguments): to run argv do shell script echo
Based on example found here but I guess I'm not understanding it. This works
I have a function to connect to a database. This code works: def connect():
How can I accomplish http://php.net/manual/en/function.call-user-func-array.php in ruby? So I can do this: class App
I have a trivial example: def func1(): local_var = None def func(args): print args,

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.