So we've had datatypes as antiform FENCE! for a while, and they look good... I think. Relatively speaking.
I'd wondered "is this a good thing to spend antiform FENCE! on", and I think it's been sort of well spent... but... I'm starting to wonder if maybe we could get a bit more bang for buck out of them.
In particular...I have wondered if we might say that DATATYPE! cannot be compared.
>> integer! = integer!
** PANIC: Datatype is not a comparable type (use TYPECHECK, MATCH)
If we were willing to say that you never compare datatypes to each other directly, then this would make them a good fit for things that wanted matching semantics:
This could be something like FIND:
>> find [a b c 10 20] integer!
== [10 20]
Or more often useful, something like SWITCH:
>> switch 10 [text! [print "Won't run"] integer! [print "This would run"]]
This would run
I've also wondered if given their not so awful looks, if they might be able to encode type constraints that are richer:
>> switch:all first [@foo:bar] [
text! [print "no"]
~{@chain!}~ [print "Yes, it's a chain"]
~{@word!:word!}~ [print "Yes, it's a chain of two words"]
]
Yes, it's a chain.
Yes, it's a chain of two words.
It looks a little funky. But right now if you want to test for an @CHAIN! in a situation like this you have to use a convoluted typechecker: chain?:pinned/
I think we've just sort of found that TYPE OF doesn't get you very far. If we took equality comparison of types fully off the table then what would happen?
Just a kind of half-formed thought here. But I guess the thing I wanted to float out there is that I'm not hating the notation with the tildes and braces for off-the-cuff creation of FENCE! antiforms to pattern match. And I like the idea of getting rid of SWITCH:TYPE. Things like this are ugly:
return-to-c switch:type state [ ; <- :TYPE is unfortunate
integer! [
assert [empty? instruction]
state
]
group! [
assert [empty? instruction]
state
]
group?:meta/ [ ; not generalized, clunky... I prefer ~{^group!}~
state
]
]