A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/exts/nullary_types.html below:

Website Navigation


6.4.1. Data types with no constructors — Glasgow Haskell Compiler 9.12.2 User's Guide

6.4.1. Data types with no constructors¶
EmptyDataDecls¶
Since:

6.8.1

Status:

Included in GHC2024, GHC2021 and Haskell2010

Allow definition of empty data types.

With the EmptyDataDecls extension, GHC lets you declare a data type with no constructors.

You only need to enable this extension if the language you’re using is Haskell 98, in which a data type must have at least one constructor. Haskell 2010 relaxed this rule to allow data types with no constructors, and thus EmptyDataDecls is enabled by default when the language is Haskell 2010.

For example:

data S      -- S :: Type
data T a    -- T :: Type -> Type

Syntactically, the declaration lacks the “= constrs” part. The type can be parameterised over types of any kind, but if the kind is not Type then an explicit kind annotation must be used (see Explicitly-kinded quantification).

Such data types have only one value, namely bottom. Nevertheless, they can be useful when defining “phantom types”.

In conjunction with the EmptyDataDeriving extension, empty data declarations can also derive instances of standard type classes (see Deriving instances for empty data types).


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4