Jump to content

Nullary constructor

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by SlamDiego (talk | contribs) at 07:21, 10 December 2006 (Creation of article.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

A nullary constructor is a constructor that takes no arguments.

Example

public class Example 
{
  // nullary constructor
  public Example()
  {
     this.data = 1;
  }
  
  // non-nullary constructor 
  public Example(int data)
  {
     this.data = data;
  }
  
  protected int data;
}

Example

-- nullary type constructor with two nullary data constructors
data Bool = False | True

-- non-nullary type constructor with non-nullary data constructor
data Point a = Point a a