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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:12:54+00:00 2026-05-30T02:12:54+00:00

I know the differences between data , newtype and type very well. I am

  • 0

I know the differences between data, newtype and type very well. I am writing a small script that will build some sort of syntax tree. Almost all types have one constructor. I am avoiding type to enforce safety (multiple “different” types might end up having the same type in Haskell). I don’t care about laziness/strictness in this case, nor do I care about performance (this part is by no means performance critical). I am mainly focused on style. I have three options:

  1. Use only data. This feels OK, except that I have many types with only one constructor with one argument. The code looks some how wasteful… Although I don’t care about the performance gain, but it just does not feel right.
  2. Use only newtype. This leads to a lot of ugliness with tuples in the case of multiple parameters.
  3. Mix data and newtype which somewhat look non-uniform and slightly annoying.. I’d rather have all types declared in a single consistent way.

I am in a dilemma of choosing between 1 and 3.

  • 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-30T02:12:56+00:00Added an answer on May 30, 2026 at 2:12 am

    In this case, I would use data universally, for a couple of reasons. Firstly, for consistency with the multiple-argument cases (which should definitely be data, not newtype).

    Secondly, and most importantly, newtype has different semantics to data! The constructor of a newtype is strict, as opposed to those of data, which are non-strict unless you explicitly use strict fields. Even if you don’t care about strictness, or all the fields of your datas are strict, there are still some subtle differences.

    I don’t think one-constructor, one-argument data types are wasteful — syntactically, they’re just as light as a newtype, and semantically, seems more important to me.

    You said you’re not concerned about performance, but if the runtime boxing overhead of a data was really inconvenient, then you could mix them, as long as you’re aware of the semantic differences. However, if you use -funbox-strict-fields, then GHC might be able to optimise away the single-constructor, single-argument datas for you, if they occur as strict fields in other data types.

    Generally, you should use newtype when you’re wrapping an existing type, for the purposes of compile-time safety/abstraction, or to define your own instances, and use data whenever the type just happens to be composed of a single field, rather than being a wrapper.

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

Sidebar

Related Questions

I know that one of the differences between classes and structs is that struct
I know that there're few differences between struct and class in C++. I also
I want to know the differences between SOA and OO, and why SOA is
Can someone please explain the major differences between Scala, Groovy and Clojure. I know
Does anyone know what substantial differences there are between the regular PostgreSQL and Postgres
I want to know the differences/similarities between Hibernate and simple persistence in Java EE
What are the main differences, advantages and disadvantages between static and dynamic data structures?
I would like to know the difference between saving data to an element using
Hi Guys I want to know what is the difference between thread safe Data
What are the main differences between PHP and Java that someone proficient in PHP

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.