DEV Community

Discussion on: Pragmatic types: what are types?

Collapse
 
jvanbruegge profile image
Jan van Brügge

Not sure why you avoided the term set, it's exactly what a type is, the set of all possible values. For example a union type in Typescript can be expressed as:

type A = number | string;
//same as
number = { n | n ∈ ℝ }
string = { s | s ∈ ∑* }
A = number ∪ string

Systems like LiquidHaskell even allow you to specify a subset of types for your functions, so you can e.g. only pass lists that are proven to not be empty to a function that extracts the first element.

Collapse
 
stereobooster profile image
stereobooster

The issue here is that sets have formal definition and if you say that types are sets you claim that types follow all formal rules for sets. I am not sure that this is the case, even that "simple" types are very similar to sets. I will need to read more to explain exact difference