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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:21:52+00:00 2026-05-25T15:21:52+00:00

Coming back to Scala after a spell writing Haskell, I’ve started using the type

  • 0

Coming back to Scala after a spell writing Haskell, I’ve started using the type keyword to make my class definitions a bit more readable, eg:

type RestfulParams = Map[String, String]
def canonicalize(params: RestfulParams): String = { ... }

The trouble I’ve run into is that these type definitions need to live inside a class or object – they’re not “first class citizens” like they are in Haskell. If I try to define a type outside of a class or object, I get a compiler expected class or object definition.

My problem then is how to use these types across multiple classes and objects in a package? What I’ve done now seems quite ugly:

object RestfulTypes { type RestfulParams = Map[String, String] etc }

And then in another class file:

import utils.{RestfulTypes => RT}
def get(resource: String, params: RT.RestfulParams): String = { ... }

Is there a nicer way of doing this – and incidentally do the Scala gurus think it’s a good thing or a bad thing that types can only be defined inside classes/objects?

  • 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-25T15:21:53+00:00Added an answer on May 25, 2026 at 3:21 pm

    Will package objects work for you?

    From the article:

    Until 2.8, the only things you could put in a package were classes, traits, and standalone objects. These are by far the most common definitions that are placed at the top level of a package, but Scala 2.8 doesn’t limit you to just those. Any kind of definition that you can put inside a class, you can also put at the top level of a package. If you have some helper method you’d like to be in scope for an entire package, go ahead and put it right at the top level of the package. To do so, you put the definitions in a package object. Each package is allowed to have one package object. Any definitions placed in a package object are considered members of the package itself.

    The package object scala has many types and values already, so I think you can use the same technique for your own types.

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

Sidebar

Related Questions

Coming back to flex after not using it for a while, trying to load
Im coming back to needing to use SQL again after not using it for
I'm coming back to c++ after using Java for a long time. In Java
i am coming back because i still have problem using JodaTime. After the previous
coming back to postgresql after several years of oracle ... what are the state-of-the
I'm trying to fetch Wikipedia pages using LWP::Simple , but they're not coming back.
I'm coming back to C++ after long years spent on other technologies and i'm
I am coming back to facebook app development after a long time. And I
I am writing an application to monitor various information coming back from an array
I'm having a lot of trouble with Ruby after coming back to it from

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.