Products
  • Wolfram|One

    The definitive Wolfram Language and notebook experience

  • Mathematica

    The original technical computing environment

  • Notebook Assistant + LLM Kit

    All-in-one AI assistance for your Wolfram experience

  • Compute Services
  • System Modeler
  • Finance Platform
  • Wolfram|Alpha Notebook Edition
  • Application Server
  • Enterprise Private Cloud
  • Wolfram Engine
  • Wolfram Player
  • Wolfram Cloud App
  • Wolfram Player App

More mobile apps

Core Technologies of Wolfram Products

  • Wolfram Language
  • Computable Data
  • Wolfram Notebooks
  • AI & Linguistic Understanding

Deployment Options

  • Wolfram Cloud
  • wolframscript
  • Wolfram Engine Community Edition
  • Wolfram LLM API
  • WSTPServer
  • Wolfram|Alpha APIs

From the Community

  • Function Repository
  • Community Paclet Repository
  • Example Repository
  • Neural Net Repository
  • Prompt Repository
  • Wolfram Demonstrations
  • Data Repository
  • Group & Organizational Licensing
  • All Products
Consulting & Solutions

We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

  • Data & Computational Intelligence
  • Model-Based Design
  • Algorithm Development
  • Wolfram|Alpha for Business
  • Blockchain Technology
  • Education Technology
  • Quantum Computation

Wolfram Consulting

Wolfram Solutions

  • Data Science
  • Artificial Intelligence
  • Biosciences
  • Healthcare Intelligence
  • Sustainable Energy
  • Control Systems
  • Enterprise Wolfram|Alpha
  • Blockchain Labs

More Wolfram Solutions

Wolfram Solutions For Education

  • Research Universities
  • Colleges & Teaching Universities
  • Junior & Community Colleges
  • High Schools
  • Educational Technology
  • Computer-Based Math

More Solutions for Education

  • Contact Us
Learning & Support

Get Started

  • Wolfram Language Introduction
  • Fast Intro for Programmers
  • Fast Intro for Math Students
  • Wolfram Language Documentation

More Learning

  • Highlighted Core Areas
  • Demonstrations
  • YouTube
  • Daily Study Groups
  • Wolfram Schools and Programs
  • Books

Grow Your Skills

  • Wolfram U

    Courses in computing, science, life and more

  • Community

    Learn, solve problems and share ideas.

  • Blog

    News, views and insights from Wolfram

  • Resources for

    Software Developers

Tech Support

  • Contact Us
  • Support FAQs
  • Support FAQs
  • Contact Us
Company
  • About Wolfram
  • Career Center
  • All Sites & Resources
  • Connect & Follow
  • Contact Us

Work with Us

  • Student Ambassador Initiative
  • Wolfram for Startups
  • Student Opportunities
  • Jobs Using Wolfram Language

Educational Programs for Adults

  • Summer School
  • Winter School

Educational Programs for Youth

  • Middle School Camp
  • High School Research Program
  • Computational Adventures

Read

  • Stephen Wolfram's Writings
  • Wolfram Blog
  • Wolfram Tech | Books
  • Wolfram Media
  • Complex Systems

Educational Resources

  • Wolfram MathWorld
  • Wolfram in STEM/STEAM
  • Wolfram Challenges
  • Wolfram Problem Generator

Wolfram Initiatives

  • Wolfram Science
  • Wolfram Foundation
  • History of Mathematics Project

Events

  • Stephen Wolfram Livestreams
  • Online & In-Person Events
  • Contact Us
  • Connect & Follow
Wolfram|Alpha
  • Your Account
  • User Portal
  • Wolfram Cloud
  • Products
    • Wolfram|One
    • Mathematica
    • Notebook Assistant + LLM Kit
    • Compute Services
    • System Modeler
    • Finance Platform
    • Wolfram|Alpha Notebook Edition
    • Application Server
    • Enterprise Private Cloud
    • Wolfram Engine
    • Wolfram Player
    • Wolfram Cloud App
    • Wolfram Player App

    More mobile apps

    • Core Technologies
      • Wolfram Language
      • Computable Data
      • Wolfram Notebooks
      • AI & Linguistic Understanding
    • Deployment Options
      • Wolfram Cloud
      • wolframscript
      • Wolfram Engine Community Edition
      • Wolfram LLM API
      • WSTPServer
      • Wolfram|Alpha APIs
    • From the Community
      • Function Repository
      • Community Paclet Repository
      • Example Repository
      • Neural Net Repository
      • Prompt Repository
      • Wolfram Demonstrations
      • Data Repository
    • Group & Organizational Licensing
    • All Products
  • Consulting & Solutions

    We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

    WolframConsulting.com

    Wolfram Solutions

    • Data Science
    • Artificial Intelligence
    • Biosciences
    • Healthcare Intelligence
    • Sustainable Energy
    • Control Systems
    • Enterprise Wolfram|Alpha
    • Blockchain Labs

    More Wolfram Solutions

    Wolfram Solutions For Education

    • Research Universities
    • Colleges & Teaching Universities
    • Junior & Community Colleges
    • High Schools
    • Educational Technology
    • Computer-Based Math

    More Solutions for Education

    • Contact Us
  • Learning & Support

    Get Started

    • Wolfram Language Introduction
    • Fast Intro for Programmers
    • Fast Intro for Math Students
    • Wolfram Language Documentation

    Grow Your Skills

    • Wolfram U

      Courses in computing, science, life and more

    • Community

      Learn, solve problems and share ideas.

    • Blog

      News, views and insights from Wolfram

    • Resources for

      Software Developers
    • Tech Support
      • Contact Us
      • Support FAQs
    • More Learning
      • Highlighted Core Areas
      • Demonstrations
      • YouTube
      • Daily Study Groups
      • Wolfram Schools and Programs
      • Books
    • Support FAQs
    • Contact Us
  • Company
    • About Wolfram
    • Career Center
    • All Sites & Resources
    • Connect & Follow
    • Contact Us

    Work with Us

    • Student Ambassador Initiative
    • Wolfram for Startups
    • Student Opportunities
    • Jobs Using Wolfram Language

    Educational Programs for Adults

    • Summer School
    • Winter School

    Educational Programs for Youth

    • Middle School Camp
    • High School Research Program
    • Computational Adventures

    Read

    • Stephen Wolfram's Writings
    • Wolfram Blog
    • Wolfram Tech | Books
    • Wolfram Media
    • Complex Systems
    • Educational Resources
      • Wolfram MathWorld
      • Wolfram in STEM/STEAM
      • Wolfram Challenges
      • Wolfram Problem Generator
    • Wolfram Initiatives
      • Wolfram Science
      • Wolfram Foundation
      • History of Mathematics Project
    • Events
      • Stephen Wolfram Livestreams
      • Online & In-Person Events
    • Contact Us
    • Connect & Follow
  • Wolfram|Alpha
  • Wolfram Cloud
  • Your Account
  • User Portal
Wolfram Language & System Documentation Center
TypeDeclaration
  • See Also
    • CompilerEnvironmentAppendTo
    • FunctionCompile
    • CompiledExpressionDeclaration
    • FunctionDeclaration
    • OperationDeclaration
    • LibraryFunctionDeclaration
    • CompilerInformation
    • ForAllType
    • CreateTypeInstance
  • Related Guides
    • Compiled Types
    • Code Compilation
  • Tech Notes
    • Wolfram Compiler Manual
    • See Also
      • CompilerEnvironmentAppendTo
      • FunctionCompile
      • CompiledExpressionDeclaration
      • FunctionDeclaration
      • OperationDeclaration
      • LibraryFunctionDeclaration
      • CompilerInformation
      • ForAllType
      • CreateTypeInstance
    • Related Guides
      • Compiled Types
      • Code Compilation
    • Tech Notes
      • Wolfram Compiler Manual

TypeDeclaration["Product",name,<|field1type1,field2type2,…|>]

represents a declaration of a product type with the specified fields.

TypeDeclaration["Abstract",name]

represents a declaration of the abstract type name.

TypeDeclaration["Alias",name,targetType]

represents a declaration of the type name using the internal representation of targetType.

TypeDeclaration["Macro",name,targetType]

represents a declaration specifying that all instances of name should be replaced with targetType.

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
"Product"  
"Abstract"  
"Alias"  
"Macro"  
Options  
"AbstractTypes"  
"Creator"  
"MemoryManaged"  
"Operations"  
"ReferenceSemantics"  
Applications  
Possible Issues  
See Also
Tech Notes
Related Guides
History
Cite this Page
BUILT-IN SYMBOL
  • See Also
    • CompilerEnvironmentAppendTo
    • FunctionCompile
    • CompiledExpressionDeclaration
    • FunctionDeclaration
    • OperationDeclaration
    • LibraryFunctionDeclaration
    • CompilerInformation
    • ForAllType
    • CreateTypeInstance
  • Related Guides
    • Compiled Types
    • Code Compilation
  • Tech Notes
    • Wolfram Compiler Manual
    • See Also
      • CompilerEnvironmentAppendTo
      • FunctionCompile
      • CompiledExpressionDeclaration
      • FunctionDeclaration
      • OperationDeclaration
      • LibraryFunctionDeclaration
      • CompilerInformation
      • ForAllType
      • CreateTypeInstance
    • Related Guides
      • Compiled Types
      • Code Compilation
    • Tech Notes
      • Wolfram Compiler Manual

TypeDeclaration

TypeDeclaration["Product",name,<|field1type1,field2type2,…|>]

represents a declaration of a product type with the specified fields.

TypeDeclaration["Abstract",name]

represents a declaration of the abstract type name.

TypeDeclaration["Alias",name,targetType]

represents a declaration of the type name using the internal representation of targetType.

TypeDeclaration["Macro",name,targetType]

represents a declaration specifying that all instances of name should be replaced with targetType.

Details and Options

  • TypeDeclaration is a symbolic representation of a declaration and does not evaluate on its own.
  • TypeDeclaration can be used inside of CompilerEnvironmentAppendTo and the first argument of functions like FunctionCompile.
  • The following kinds of declarations are supported:
  • "Product"a type containing several fields; analogous to a struct in C
    "Abstract"an abstract type that concrete types can be instances of; a type class
    "Alias"a type that uses the same internal implementation as another type
    "Macro"a replacement rule that is applied to all types
  • When interfacing with C-compatible programs, the following type declarations are equivalent:
  • TypeDeclaration["Product",
    "myStruct",
    <|"f1"->"CInt","f2"->"CDouble"|>,
    "ReferenceSemantics"->False]
    struct myStruct {int f1; double f2;};
    TypeDeclaration["Macro","myInteger","CInt"]typedef int myInteger;
  • The fields of a product type instance prod can be accessed and set with prod["field"].
  • The following options are supported:
  • "AbstractTypes"{}abstract types containing the declared type
    "Creator"Nonea function to call to create an instance of the declared type
    "MemoryManaged"Automaticwhether to automatically free unreferenced instances
    "Operations"{}operations that are available for the declared type
    "ReferenceSemantics"Automaticwhether to internally represent the type with a pointer
  • By default, "Product" declarations have "MemoryManaged"True and "ReferenceSemantics"True.
  • "ReferenceSemantics" can only be set to True for "Product" declarations.
  • "MemoryManaged" can only be set to True for "Product" declarations with reference semantics.
  • "Creator" can only be set for "Product" declarations .
  • "Operations" can only be set for "Product" and "Abstract" declarations .
  • "AbstractTypes" cannot be set for "Macro" declarations.
  • For compatibility with C structs, product types must generally set "MemoryManaged" and "ReferenceSemantics" generally must be set to False.
  • The following methods are defined for objects prod that are instances of product types:
  • prod["field"]get the value of "field"
    prod["field"]=valset the value of "field"
    DeleteObject[prod]free prod (only available if prod is not memory managed)

Examples

open all close all

Basic Examples  (2)

Represent a declaration of "fooInteger" as a macro type for "MachineInteger":

Compile a function using the declaration:

Globally declare "fooInteger" as a macro for "MachineInteger":

Compile a function using "fooInteger":

Reset the compiler environment to clear the declaration:

Scope  (6)

"Product"  (2)

A declaration of a product type:

Compile a function that instantiates a product type and then extracts a field:

A declaration of a polymorphic product type:

Compile a function that accepts a machine integer and uses it to create the product type above:

"Abstract"  (1)

A declaration of an abstract type:

A declaration of a product type that is an instance of the abstract type:

A declaration of a product type that is not an instance of the abstract type:

A declaration of a function that accepts any instance of the abstract type:

Compile a program using the function on a type that is an instance of the abstract type:

The function does not accept inputs from types that are not instances of the abstract type:

"Alias"  (1)

An alias for the "String" type:

A function for the alias that differs from its implementation on the original type:

Compile a program that instantiates the alias through bitcasting and then evaluates the function on it:

"Macro"  (2)

A macro for the "String" type:

A function that refers to "String" using the macro:

Macros are not types, but replacement rules that are applied to types when they are resolved. Therefore, it is impossible to have different definitions of the same function for a macro and the type to which it refers:

Unlike macros, aliases are types, so functions can recognize whether they are applied to a type or an alias of that type.

Options  (11)

"AbstractTypes"  (2)

Represent an abstract type:

Represent an object that is a member of the abstract type:

Represent a function that accepts any instance of the abstract type:

Compile the function, showing that it accepts the product type that is a member of the abstract type:

Represent an abstract type:

Represent another abstract type that is a member of the first:

Represent a product type that is an instance of the second abstract type:

Represent a function that accepts any instance of the abstract type "superType":

Compile the function, showing that it accepts the product type that inherited membership in "superType" through "subType":

"Creator"  (1)

Represent a type with its own creation function:

Represent the implementation of the creation function:

Compile a function that uses CreateTypeInstance and calls the "Creator" function:

The result is 10 as expected:

"MemoryManaged"  (3)

Represent a type without automatic memory management:

Compile a function that uses the type:

The resulting function leaks memory because the object is not automatically freed:

By default, product types are automatically memory managed:

The function that uses the memory-managed type does not leak memory:

Represent a type without automatic memory management:

Compile a function that uses the type and frees it with DeleteObject:

The resulting function does not leak memory because it was manually freed:

Memory-managed product types include a reference count and are not compatible with external programs. When passing a product type to and from a library function, memory management should be disabled.

Compile a library defining a struct foo:

Represent a compatible type with TypeDeclaration:

Note that the compiled type "foo" is a reference type by default, and is equivalent to foo* in C.

Compile a function that calls the library using the type:

"Operations"  (3)

A declaration of a product type with one operation:

A declaration of the operation:

Compile a function to create an instance of the type and another to call the "Increment" operation:

Create the instance:

Call the "Increment" operation; the old value of 0 is returned:

Call the "Increment" operation again; now the old value is 1:

Operations can also be defined for an abstract type. In this case, they are available for any type that implements the abstract type.

Represent an abstract type:

Represent an object that implements the abstract type:

A declaration of the operation:

Compile a function to create an instance of the type and another to call the "Increment" operation:

Create the instance:

Call the "Increment" operation; the old value of 0 is returned:

Call the "Increment" operation again; now the old value is 1:

Operations defined for an abstract type can refer to an actual implementation:

Represent an abstract type:

A declaration of the operation; it is written polymorphically with ForAllType:

Represent an object that is a member of the abstract type:

Compile a function to create an instance of the type and another to call the "Increment" operation:

Create the instance:

Call the "Increment" operation; the old value of 0 is returned:

Call the "Increment" operation again; now the old value is 1:

The implementation of the operation is entirely set up by the abstract type.

A different implementation of an operation can be given. Since it is declared in a narrower way, using the actual type, it overrides that given from the abstract type:

Compile a function to create an instance of the type and another to call the "Increment" operation:

Create the instance:

Now the "Increment" operation is different:

"ReferenceSemantics"  (2)

Represent a type that will be passed by value instead of by reference:

Compile a function using the value type:

Compile a library defining a struct foo:

Represent a compatible type with TypeDeclaration:

Compile a function using the type:

Applications  (1)

The C standard library includes a function called ldiv that computes the quotient and remainder of two integers. It returns an object declared as:

typedef struct {
    long quot; /* quotient */
    long rem; /* remainder */
} ldiv_t;

Represent the declaration of the ldiv_t type:

Represent the declaration of the ldiv function:

Compile a program that calls the function from the C standard library:

Possible Issues  (1)

Macros are not types, but replacement rules that are applied to types when they are resolved. Therefore, it is impossible to have different definitions of the same function for a macro and the type to which it refers:

Unlike macros, aliases are types, so functions can recognize whether they are applied to a type or an alias of that type.

See Also

CompilerEnvironmentAppendTo  FunctionCompile  CompiledExpressionDeclaration  FunctionDeclaration  OperationDeclaration  LibraryFunctionDeclaration  CompilerInformation  ForAllType  CreateTypeInstance

Tech Notes

    ▪
  • Wolfram Compiler Manual

Related Guides

    ▪
  • Compiled Types
  • ▪
  • Code Compilation

History

Introduced in 2022 (13.1)

Wolfram Research (2022), TypeDeclaration, Wolfram Language function, https://reference.wolfram.com/language/ref/TypeDeclaration.html.

Text

Wolfram Research (2022), TypeDeclaration, Wolfram Language function, https://reference.wolfram.com/language/ref/TypeDeclaration.html.

CMS

Wolfram Language. 2022. "TypeDeclaration." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TypeDeclaration.html.

APA

Wolfram Language. (2022). TypeDeclaration. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TypeDeclaration.html

BibTeX

@misc{reference.wolfram_2025_typedeclaration, author="Wolfram Research", title="{TypeDeclaration}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/TypeDeclaration.html}", note=[Accessed: 01-May-2026]}

BibLaTeX

@online{reference.wolfram_2025_typedeclaration, organization={Wolfram Research}, title={TypeDeclaration}, year={2022}, url={https://reference.wolfram.com/language/ref/TypeDeclaration.html}, note=[Accessed: 01-May-2026]}

Top
Introduction for Programmers
Introductory Book
Wolfram Function Repository | Wolfram Data Repository | Wolfram Data Drop | Wolfram Language Products
Top
  • Products
  • Wolfram|One
  • Mathematica
  • Notebook Assistant + LLM Kit
  • Compute Services
  • System Modeler

  • Wolfram|Alpha Notebook Edition
  • Wolfram|Alpha Pro
  • Mobile Apps

  • Wolfram Engine
  • Wolfram Player

  • Volume & Site Licensing
  • Server Deployment Options
  • Consulting
  • Wolfram Consulting
  • Repositories
  • Data Repository
  • Function Repository
  • Community Paclet Repository
  • Neural Net Repository
  • Prompt Repository

  • Wolfram Language Example Repository
  • Notebook Archive
  • Wolfram GitHub
  • Learning
  • Wolfram U
  • Wolfram Language Documentation
  • Webinars & Training
  • Educational Programs

  • Wolfram Language Introduction
  • Fast Introduction for Programmers
  • Fast Introduction for Math Students
  • Books

  • Wolfram Community
  • Wolfram Blog
  • Public Resources
  • Wolfram|Alpha
  • Wolfram Problem Generator
  • Wolfram Challenges

  • Computer-Based Math
  • Computational Thinking
  • Computational Adventures

  • Demonstrations Project
  • Wolfram Data Drop
  • MathWorld
  • Wolfram Science
  • Wolfram Media Publishing
  • Customer Resources
  • Store
  • Product Downloads
  • User Portal
  • Your Account
  • Organization Access

  • Support FAQ
  • Contact Support
  • Company
  • About Wolfram
  • Careers
  • Contact
  • Events
Wolfram Community Wolfram Blog
Legal & Privacy Policy
WolframAlpha.com | WolframCloud.com
© 2026 Wolfram
© 2026 Wolfram | Legal & Privacy Policy |
English