Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define what "Type" means

Tags:

c#

.net

types

clr

Excerpt from Eric Lippert's Blog about What the meaning of "is", is:

A common conception of types is that a type is a set [...] of values, and that assignment compatibility is merely checking to see if a given value is a member of the necessary set. But that’s not the case in C#.

The counter example he gives is that null is string returns false, but string b = null is totally fine by the C# compiler.

Perhaps this is a silly question, but what is a better way to define the idea of "type" in a C#.Net context? Is it just a word used to define ... memory footprint rules? ... to the CLR? I realize how loose (and horribly wrong) that definition is, but I'm struggling to fit a nice wrapper and bow around the idea of type.

Note: the simpler, yet completely accurate, the better. (strong N type, here).

like image 274
Frank Bryce Avatar asked Jun 30 '15 02:06

Frank Bryce


People also ask

What do you mean by type?

noun. a number of things or persons sharing a particular characteristic, or set of characteristics, that causes them to be regarded as a group, more or less precisely defined or designated; class; category: a criminal of the most vicious type.

What are the 4 types of definition?

Here are just four among the many types of definitions: (1) Definition by synonym; (2) Ostensive definitions; (3) Stipulative definitions, and. (4) Analytical definitions.

What are the 3 types of definition?

All definitions attempt to explain or clarify a term. This lesson will introduce you to the three different types of definitions: formal, informal, and extended.


1 Answers

what is a better way to define the idea of "type" in a C#.Net context? Is it just a word used to define ... memory footprint rules? I'm struggling to fit a nice wrapper and bow around the idea of type.

This is a tricky problem. You opened with a link to my article about is, but I think the one you really want to read is this one:

http://blogs.msdn.com/b/ericlippert/archive/2011/08/29/what-is-this-thing-you-call-a-quot-type-quot-part-one.aspx

http://blogs.msdn.com/b/ericlippert/archive/2011/09/07/what-is-this-thing-you-call-a-quot-type-quot-part-two.aspx

Briefly:

From a "mathematical" point of view, a type is like a number: an abstract quantity that we can manipulate using rules. Like "if T is a type then T[] is also a type", and so on.

Once we have an abstract notion of type then we can assign every expression a type, and then we can make a verifier that automatically determines whether a program follows the type safety rules or not.

like image 109
Eric Lippert Avatar answered Oct 04 '22 16:10

Eric Lippert