Nullary constructor

Nullary constructor

Contents

In computer programming, a nullary constructor is a constructor that takes no arguments.

Object-oriented constructors

In object-oriented programming, a constructor is code that is run when an object is created. Default constructors of objects are usually nullary.

Java example

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

Algebraic data types

In algebraic data types, a constructor is one of many tags that wrap data. If a constructor does not take any data arguments, it is nullary.

Haskell example

 -- nullary type constructor with two nullary data constructors
 data Bool = False
           | True
 
 -- non-nullary type constructor with one non-nullary data constructor
 data Point a = Point a a
 
 -- non-nullary type constructor with...
 data Maybe a = Nothing -- ...nullary data constructor
              | Just a  -- ...unary data constructor



Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • Constructor — Als Konstruktoren und Destruktoren werden in der Programmierung spezielle Prozeduren bezeichnet, die beim Erzeugen und Zerstören von Objekten oder Variablen aufgerufen werden. Konstruktoren bringen die Objekte in einen definierten Anfangszustand …   Deutsch Wikipedia

  • Default constructor — In computer programming languages the term “default constructor” refers to a constructor that is automatically generated in the absence of explicit constructors (and perhaps under other circumstances); this automatically provided constructor is… …   Wikipedia

  • Нуль-арный конструктор — В компьютерном программировании нуль арным конструктором (в англ. языке используется термин nullary constructor) называют конструктор, не принимающий аргументы. Содержание 1 Объектно ориентированные конструкторы 1.1 …   Википедия

  • Konstruktoren und Destruktoren — Als Konstruktoren und Destruktoren (aus dem Englischen auch kurz ctor bzw. dtor genannt) werden in der Programmierung spezielle Prozeduren bzw. Methoden bezeichnet, die beim Erzeugen und Auflösen von Objekten und Variablen aufgerufen werden.… …   Deutsch Wikipedia

  • Destruktor — Als Konstruktoren und Destruktoren werden in der Programmierung spezielle Prozeduren bezeichnet, die beim Erzeugen und Zerstören von Objekten oder Variablen aufgerufen werden. Konstruktoren bringen die Objekte in einen definierten Anfangszustand …   Deutsch Wikipedia

  • Konstruktor — Als Konstruktoren und Destruktoren werden in der Programmierung spezielle Prozeduren bezeichnet, die beim Erzeugen und Zerstören von Objekten oder Variablen aufgerufen werden. Konstruktoren bringen die Objekte in einen definierten Anfangszustand …   Deutsch Wikipedia

  • Enumerated type — In computer programming, an enumerated type is a data type (usually user defined) consisting of a set of named constants called enumerators . The act of creating an enumerated type defines an enumeration. When an identifier such as a variable is… …   Wikipedia

  • Algebraic data type — In computer programming, particularly functional programming and type theory, an algebraic data type (sometimes also called a variant type[1]) is a datatype each of whose values is data from other datatypes wrapped in one of the constructors of… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”