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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:05:26+00:00 2026-06-16T01:05:26+00:00

After a lot of Java and some Haskell I wanted to have a look

  • 0

After a lot of Java and some Haskell I wanted to have a look at Scala. From the code below, I’m getting this error message

type mismatch; found : List[Nothing] => Option[Nothing] required: List[Int] => Option[Nothing]

I don’t know what I’m doing wrong:

object MyFirstScalaObject {

  def main(args: Array[String]) {
      lazy val testValues:List[List[Int]] = List((1 to 10).toList, null, List());

      println(  testFunction(last, testValues));
  }

  def testFunction[I, O](f : I => O, inputs : List[I]):
      List[(I, O)] = 
    inputs.zip(inputs.map(f));

  def last[A](xs:List[A]):Option[A] = xs match {
    case x::Nil => Some(x);
    case _::xs => last(xs);
    case _ => None;
  }

}

Thanks for any advice.

Cheers,

  • 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-16T01:05:27+00:00Added an answer on June 16, 2026 at 1:05 am

    because of the way type inference works in scala, it is unable to determine the what the type parameter to last has to be, so it has to take the overly conservative fallback guess that it is Nothing.

    You can explicitly specify the types when you call testFunction:

    testFunction[List[Int],Option[Int](last, testValues)
    

    or you can document more fully the relationship between the type parameters in the testFunction declaration, which will give the type inferencer more information:

    def testFunction[A, I[_], O[_]](f : I[A] => O[A], inputs : List[I[A]]): List[(I[A], O[A])]
    

    This explicitly says that I and O are type constructors (kind * -> *), now that the input/output types of f are more specific, the inferencer can correctly infer that the A parameter to the the last function must be Int.

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

Sidebar

Related Questions

When i run my java program from bash script, after some times i receive
After doing lot of research in Google, I found this program: #include <stdio.h> int
After read a lot about ball physics, watch some examples and few days of
A lot of JavaScript libraries have user interface widgets. Usually they are created after
After doing some research on the subject, I've been experimenting a lot with patterns
I have read a lot about the Java class loading process lately. Often I
hey i made a lot of search and found some similar types of code.
I have question on usage java nio and hope someone who has a lot
The index.jsp contains java codes which will fetch some images and texts from a
This might seem like a silly question, but after asking some questions on stackoverflow

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.