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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:10:57+00:00 2026-05-31T23:10:57+00:00

I am trying to use the new immutable OptionParser in the Scala scopt 2.0.1

  • 0

I am trying to use the new immutable OptionParser in the Scala scopt 2.0.1 library. Since OptionParser takes a generic type and the help method already defines an action that returns Unit, I am getting a compile-time error:

case class Config(directory: String = null)

val parser = new OptionParser[Config]() {
  def options = Seq(
    opt("d", "directory", "directory containing the files to be processed") {
      (value: String,  config: Config) => config.copy(directory = value)
    },
    help("?", "help", "Show a usage message and exit"))
}

error: type mismatch;
[INFO]  found   : scopt.generic.FlagOptionDefinition[Nothing]
[INFO]  required: scopt.generic.OptionDefinition[Config]
[INFO] Note: Nothing <: Config, but class OptionDefinition is invariant in type C.

How can I include a “help” option?

  • 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-31T23:10:58+00:00Added an answer on May 31, 2026 at 11:10 pm

    First of all, there seems to be an error in the library, where one of the overloaded methods of opt takes a type parameter C which it shouldn’t — at least from what I can tell. It should just take C from the class. Anyway, although you use that call, I guess Scala still correctly infers that this C is the same as the class’s C (Config).

    The problem seems to be that help is completely useless — it gives you FlagOptionDefinition[Nothing] because its action: => C implementation is {this.showUsage; exit}.

    I think that the OptionParser class needs fixing…

    You could write your own help method that enforces the C type parameter:

    def help2(shortopt: String, longopt: String, description: String) =
      new FlagOptionDefinition[C](Some(shortopt), longopt, description, 
        { this.showUsage; exit })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use the new DATETIMEOFFSET data type in SQL 2008 but
I'm trying to use the new Java 7 Files.createSymbolicLink() method within Play! Framework, and
I am trying to use the New Methods for National Character Set Type Data
I am relatively new to CMake, and I'm trying use the boost asio library
I am trying to use nunits new way of exception handling but I am
I'm trying to use the new OpenCV 2.0 API in MS Visual C++ 2008
I've been trying to use the new jquery-ui, and all but the resizable function
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,
I'm trying to use SubSonic for a new project with an existing database but

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.