R
by ReD_CoDE on 2 Nov 2020, edited 4 Nov 2020
#
Do you know any programming language that supports these types?
Data types:
-
Primitive
-
TYPE name = BOOLEAN;
-
TYPE name = BINARY;
-
TYPE name = LOGICAL;
-
TYPE name = INTEGER, {1 <= SELF <= 7};
-
TYPE name = REAL, {0.0 <= SELF <= 1.0};
-
TYPE name = NUMBER, SELF IN ['value1', 'value2', ...];
-
Composite
-
TYPE name = SET [number : ?] OF type/entity;
-
TYPE name = ARRAY [number : number] OF type/entity;
-
TYPE name = LIST [number : number] OF type/entity;
-
TYPE name = SELECT(value1,value2,...);
-
TYPE name = ENUMERATION OF (value1,value2,...);
-
TYPE name = STRING;
-
TYPE name = STRING(number);
-
TYPE name = STRING(number) FIXED;
-
TYPE name = type, SELF IN ['value1', 'value2', ...];
-
TYPE name = type, {1 <= SELF <= 7};
CC: Thomas @aothms, Stephen @stephen_l, Dion @Moult?
R
by ReD_CoDE on 2 Nov 2020
#
For instance, arrays have this pattern:
In C++
int ages[] = {49, 48, 26, 19, 16};
ages[0] = 49;
In Python
ages = [49, 48, 26, 19, 16]
So, I'm looking for a schema and/or language that supports this:
int ages[] = {0 <= SELF <= 120};
M
by Moult on 2 Nov 2020
#
I think pretty much every language out there can handle what you've listed. Languages typically let you define your own data and / or object structures.
Your third example I guess in Python may be ages = range(0, 121)
.
R
by ReD_CoDE on 2 Nov 2020
#
@Moult I mean types can have range?
And some similar notions I shared at the first comment from IFC EXPRESS?
M
by Moult on 2 Nov 2020
#
@ReD_CoDE sure it can.
class express_array(list):
def append(self, item):
list.append(self, item)
if len(self) > 120: del self[0]
R
by ReD_CoDE on 2 Nov 2020, edited 2 Nov 2020
#
+1 votes
@Moult yes, but I don't talk about that kind
I talk about types that natively support ranges and some similar notions, and as far as I know for instance Haskell somewhat support them
Those types have a specific name
M
by Moult on 2 Nov 2020
#
+1 votes
What I've shown is how programming languages work. A "native" type is always defined somewhere.
A
by antont on 3 Nov 2020, edited 3 Nov 2020
#
+1 votes
Algebraic data types. Haskell indeed is one of the relatively few languages that support them nicely. But you can sort of trivially program constraints for values in any programming language. This article discusses such types nicely and uses Javascript for examples: https://jrsinclair.com/articles/2019/algebraic-data-types-what-i-wish-someone-had-explained-about-functional-programming/
One of the Javascript 'types' is simply:
class Digit {
constructor (c) {
const validDigits = '1234567890';
if ((c.toString().length > 1) || (!validDigits.includes(c.toString()))) {
throw new Error('Digit can only contain single digits');
}
this.value = parseInt(c, 10);
Object.freeze(this);
}
}
So you could easily put any validation there, for example min & max for range or whatever.
To conclude that article notes:
languages like Haskell they have a feature called pattern matching. That type checking and the fallback case I’ve included are really just noise. (e.g. the bit with || (() => <ErrorCard />) .With pattern matching and type checking you don’t have to add that fallback. The compiler can look at the types and tell you if you’ve missed a case. And if you have covered all the cases, the compiler can guarantee that you’ll never get an unknown type. These compiler features make sum types convenient to work with.
Pattern matching, in particular, offers features a bit like destructuring. This lets you pull bits of data out from the left-hand-side of the pattern match. Again, making sum types really convenient to work with. So, sadly, the functional programmer is somewhat justified in looking smug here. TypeScript and Flow have some support for algebraic data types. But they’re both fairly limited.
S
by stephen_l on 4 Nov 2020
#
+1 votes
Python provide "compile time" type checking using type hints (pep 484)
R
by ReD_CoDE on 4 Nov 2020, edited 4 Nov 2020
#
Hi Stephen @stephen_l, I think @antont and you, and even Dion mentioned closely
I'm looking for a programming language, but mainly a schema (file format), that supports validation and deduplication and dependent types