Paste: metaclay
Author: | kssreeram |
Mode: | text |
Date: | Tue, 16 Nov 2010 07:15:17 |
Plain Text |
//
// mapValues
//
function mapValues;
[f, first, ...rest]
overload mapValues(f, first, ...rest) = f(first), ...mapValues(f, ...rest);
[f]
overload mapValues(f) = ;
//
// clay types as symbols
//
symbol Bool;
symbol Int;
symbol Array[T,n];
symbol Tuple[...T];
symbol RecordTag;
[...fields]
recordType(...fields) = (RecordTag, fieldNames(...fields), fieldTypes(...fields));
[...fields]
fieldNames(...fields) = (...mapValues(f => tupleElement(f, 0), ...fields));
[...fields]
fieldTypes(...fields) = (...mapValues(f => tupleElement(f, 1), ...fields));
[t]
record?(t) =
symbolWithBody?(t)
and tupleWithTag?(symbolBody(t), RecordTag);
[x]
symbolWithBody?(x) = symbol?(x) and symbolHasBody?(x);
[x, tag]
tupleWithTag?(x, tag) =
tuple?(x)
and lesser?(0, tupleSize(x))
and equals?(tupleElement(x, 0), tag);
[t | record?(t)]
recordFieldCount(t) = tupleSize(tupleElement(symbolBody(t), 1));
[t | record?(t)]
recordFieldNames(t) = tupleElement(symbolBody(t), 1);
[t | record?(t)]
recordFieldTypes(t) = tupleElement(symbolBody(t), 2);
symbol Point[T] = recordType(
("x", T),
("y", T),
);
[t | record?(t)]
recordInfo(t) = (t, recordFieldNames(t), recordFieldTypes(t));
main() = recordInfo(Point[Int]);
Author: | kssreeram |
Mode: | text |
Date: | Tue, 16 Nov 2010 07:16:12 |
Plain Text |
//
// mapValues
//
function mapValues;
overload mapValues('f, 'first, ...'rest) = f(first), ...mapValues(f, ...rest);
overload mapValues('f) = ;
//
// clay types as symbols
//
symbol Bool;
symbol Int;
symbol Array[T,n];
symbol Tuple[...T];
symbol RecordTag;
recordType(...'fields) = (RecordTag, fieldNames(...fields), fieldTypes(...fields));
fieldNames(...'fields) = (...mapValues(f => tupleElement(f, 0), ...fields));
fieldTypes(...'fields) = (...mapValues(f => tupleElement(f, 1), ...fields));
record?('t) =
symbolWithBody?(t)
and tupleWithTag?(symbolBody(t), RecordTag);
symbolWithBody?('x) = symbol?(x) and symbolHasBody?(x);
tupleWithTag?('x, 'tag) =
tuple?(x)
and lesser?(0, tupleSize(x))
and equals?(tupleElement(x, 0), tag);
[| record?(t)]
recordFieldCount('t) = tupleSize(tupleElement(symbolBody(t), 1));
[| record?(t)]
recordFieldNames('t) = tupleElement(symbolBody(t), 1);
[| record?(t)]
recordFieldTypes('t) = tupleElement(symbolBody(t), 2);
symbol Point[T] = recordType(
("x", T),
("y", T),
);
[| record?(t)]
recordInfo('t) = (t, recordFieldNames(t), recordFieldTypes(t));
main() = recordInfo(Point[Int]);
Author: | kssreeram |
Mode: | text |
Date: | Tue, 16 Nov 2010 07:17:45 |
Plain Text |
//
// mapValues
//
function mapValues;
overload mapValues('f, 'first, ...'rest) = f(first), ...mapValues(f, ...rest);
overload mapValues('f) = ;
//
// clay types as symbols
//
symbol Bool;
symbol Int;
symbol Array[T,n];
symbol Tuple[...T];
symbol RecordTag;
recordType(...'fields) = (RecordTag, fieldNames(...fields), fieldTypes(...fields));
fieldNames(...'fields) = (...mapValues(f => tupleElement(f, 0), ...fields));
fieldTypes(...'fields) = (...mapValues(f => tupleElement(f, 1), ...fields));
record?('t) =
symbolWithBody?(t)
and tupleWithTag?(symbolBody(t), RecordTag);
symbolWithBody?('x) = symbol?(x) and symbolHasBody?(x);
tupleWithTag?('x, 'tag) =
tuple?(x)
and lesser?(0, tupleSize(x))
and equals?(tupleElement(x, 0), tag);
recordFieldCount('t | record?(t)) = tupleSize(tupleElement(symbolBody(t), 1));
recordFieldNames('t | record?(t)) = tupleElement(symbolBody(t), 1);
recordFieldTypes('t | record?(t)) = tupleElement(symbolBody(t), 2);
symbol Point[T] = recordType(
("x", T),
("y", T),
);
recordInfo('t | record?(t)) = (t, recordFieldNames(t), recordFieldTypes(t));
main() = recordInfo(Point[Int]);
Author: | kssreeram |
Mode: | text |
Date: | Tue, 16 Nov 2010 07:32:59 |
Plain Text |
//
// mapValues
//
function mapValues;
overload mapValues('f, 'first, ...'rest) = f('first), ...mapValues('f, ...'rest);
overload mapValues('f) = ;
//
// clay types as symbols
//
symbol Bool;
symbol Int;
symbol Array[T, n];
symbol Tuple[...T];
symbol RecordTag;
recordType(...'fields) = (RecordTag, fieldNames(...'fields), fieldTypes(...'fields));
fieldNames(...'fields) = (...mapValues(f => tupleElement(f, 0), ...'fields));
fieldTypes(...'fields) = (...mapValues(f => tupleElement(f, 1), ...'fields));
record?('t) =
symbolWithBody?('t)
and tupleWithTag?(symbolBody('t), RecordTag);
symbolWithBody?('x) = symbol?('x) and symbolHasBody?('x);
tupleWithTag?('x, 'tag) =
tuple?('x)
and lesser?(0, tupleSize('x))
and equals?(tupleElement('x, 0), tag);
recordFieldCount('t | record?('t)) = tupleSize(tupleElement(symbolBody('t), 1));
recordFieldNames('t | record?('t)) = tupleElement(symbolBody('t), 1);
recordFieldTypes('t | record?('t)) = tupleElement(symbolBody('t), 2);
symbol Point[T] = recordType(
("x", T),
("y", T),
);
[record?('t)]
recordInfo('t) = ('t, recordFieldNames('t), recordFieldTypes('t));
main() = recordInfo(Point[Int]);
Author: | kssreeram |
Mode: | text |
Date: | Tue, 16 Nov 2010 07:53:12 |
Plain Text |
//
// mapValues
//
function mapValues;
overload mapValues('f, 'first, ...'rest) = f('first), ...mapValues('f, ...'rest);
overload mapValues('f) = ;
//
// clay types as symbols
//
symbol Bool;
symbol Int;
symbol Array['T, 'n];
symbol Tuple[...'T];
symbol RecordTag;
recordType(...'fields) = (RecordTag, fieldNames(...'fields), fieldTypes(...'fields));
fieldNames(...'fields) = (...mapValues(f => tupleElement(f, 0), ...'fields));
fieldTypes(...'fields) = (...mapValues(f => tupleElement(f, 1), ...'fields));
record?('t) =
symbolWithBody?('t)
and tupleWithTag?(symbolBody('t), RecordTag);
symbolWithBody?('x) = symbol?('x) and symbolHasBody?('x);
tupleWithTag?('x, 'tag) =
tuple?('x)
and lesser?(0, tupleSize('x))
and equals?(tupleElement('x, 0), tag);
recordFieldCount('t) | record?('t) = tupleSize(tupleElement(symbolBody('t), 1));
recordFieldNames('t) | record?('t) = tupleElement(symbolBody('t), 1);
recordFieldTypes('t) | record?('t) = tupleElement(symbolBody('t), 2);
symbol Point['T] = recordType(
("x", 'T),
("y", 'T),
);
recordInfo('t) | record?('t) = ('t, recordFieldNames('t), recordFieldTypes('t));
main() = recordInfo(Point[Int]);
Author: | kssreeram |
Mode: | text |
Date: | Tue, 16 Nov 2010 08:01:00 |
Plain Text |
//
// mapValues
//
function mapValues;
overload mapValues('f, 'first, ...'rest) = f('first), ...mapValues('f, ...'rest);
overload mapValues('f) = ;
//
// clay types as symbols
//
symbol Bool;
symbol Int;
symbol Array['T, 'n];
symbol Tuple[...'T];
symbol RecordTag;
recordType(...'fields) = (RecordTag, fieldNames(...'fields), fieldTypes(...'fields));
fieldNames(...'fields) = (...mapValues(f => tupleElement(f, 0), ...'fields));
fieldTypes(...'fields) = (...mapValues(f => tupleElement(f, 1), ...'fields));
record?('t) =
symbolWithBody?('t)
and tupleWithTag?(symbolBody('t), RecordTag);
symbolWithBody?('x) = symbol?('x) and symbolHasBody?('x);
tupleWithTag?('x, 'tag) =
tuple?('x)
and lesser?(0, tupleSize('x))
and equals?(tupleElement('x, 0), 'tag);
recordFieldCount('t) | record?('t) = tupleSize(tupleElement(symbolBody('t), 1));
recordFieldNames('t) | record?('t) = tupleElement(symbolBody('t), 1);
recordFieldTypes('t) | record?('t) = tupleElement(symbolBody('t), 2);
symbol Point['T] = recordType(
("x", 'T),
("y", 'T),
);
recordInfo('t) | record?('t) = ('t, recordFieldNames('t), recordFieldTypes('t));
main() = recordInfo(Point[Int]);
New Annotation