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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:03:46+00:00 2026-05-16T12:03:46+00:00

Does D have ‘newtype’ (as in Haskell). It’s a naive question, as I’m just

  • 0

Does D have ‘newtype’ (as in Haskell).

It’s a naive question, as I’m just skimming D, but Google didn’t turn up anything useful.

In Haskell this is a way of making different types of the same thing distinct at compile time, but without incurring any runtime performance penalties.

e.g. you could make newtypes (doubles) for metres, seconds and kilograms. This would error at compile time if your program added a quantity in metres to a quantity in seconds, but would be just as fast at runtime as if both were doubles (which they are at runtime).

If D doesn’t have something analogous to ‘newtype’, what are the accepted methods for dealing with dimensioned quantities?

Thanks,

Chris.

  • 1 1 Answer
  • 1 View
  • 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-16T12:03:47+00:00Added an answer on May 16, 2026 at 12:03 pm

    In D1.0 there is typedef, which is the strong typing from a predefined type to a ‘newtype.’

    D2.0 has removed this and only alias remains (what typedef is in C). There is talk about having a wrapper template that can strongly create a new type.

    The issue with typedef was that there were good arguments for making the newtype a sub-type of the predefined type, and also good arguments for making it a super-type.

    The semantics of typedef are that the base type is implicitly converted to the newtype, but the newtype is not converted to the base type or other types with the same base type. I am using base type here since:

    typedef int Fish;
    typedef Fish Cat;
    Fish gold = 1;
    Cat fluff = gold;
    

    Will fail to compile.

    And as of right now, 2.048 DMD still allows the use of typedef (but don’t use it).

    Having the base type convert to the newtype is useful so you don’t have to write

    meters = cast(meters) 12.7;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a conceptual question but I think it does have an 'answer', hopefully
I'm parsing a string that doesn't have a delimiter but does have specific indexes
Dotcms does have a nice template system based on velocity, but it seems like
In the popup window, selText does have the value great, but the length is
I have created a new table with no primary key. But the table does
The WinForm PropertyGrid copes well with a standard enum but does does have a
This is mostly an experiment , but I do think it does have some
I have a Java servlet website, but does not use any frameworks like Spring
The Math object does not have a prototype property, but does have a constructor
I'm using the official C# mongodb driver, and it does have LINQ support. 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.