I would like to build a kind of type hierarchy in Isabelle:
B is of type A ( B::A )
C and D are of type of B (C,D ::B)
E and F are of type of C (E,F ::C)
What is the best way to encode this in Isabelle? Is there any direct way to define this hierarchy, or I need a workaround. Where should I look?
PS: Suppose A..F are all abstract and some functions are defined over each type)
Thanks
(1st Note: In my opinion, as you've been using it, the word "abstract" doesn't have clear meaning. The Isabelle keywords used to define types can be used to define, as I see it, either abstract or concrete types, or types that can be considered both, such as
'a list
.)(2nd Note: Here, I take into consideration your comparisons, in other questions, to object-oriented programming. As to programming languages and languages of logic, it should be noted, I am a mere observer.)
Terms have types, and types have types (or sorts, so they say)
For myself, it all becomes a big blur, and in my mind I stop clearly differentiating between terms and types, so answers such as Rene Thiemann's help to bring that back to mind.
Still, not knowing much, I can simply consider your phrase "type hierarchy" to be synonymous with "type class hierarchy", and further to be synonymous with "sort hierarchy". That allows me to happily provide an answer to your question, though acceptance by others could be precarious.
Of course, in the Isabelle vocabulary, types and sorts aren't synonymous, but in Isabelle/HOL, they are inseparable because every HOL term has a sort. (A dangerous claim, since type
prop
is used in HOL, and maybe I still don't understand what the empty sort is.):'a::type
Inheritance, Isabelle's got it
It's through locales that Isabelle provides inheritance (among other ways?), where a type class is (or includes), among other things, a locale:
I create 5 type classes which meet your requirements, at least simplistically. Each one has its own identity function. The
+
symbol is the magical inheritance symbol.It works:
More examples of the inheritance:
Now, add some concreteness by instantiating
nat
as type classcF
:I still try, periodically, to learn how to use the Isabelle vocabulary correctly. So, I was looking at the keyword
subclass
:subclass
, page 97 isar-ref.pdfI might as well prove that
cF
is a subclass ofcA
, to make a point:Is
cA
a subclass ofcF
or vice-versa? Well, I wouldn't have already committed if I hadn't of replacedc
andd
in the definition for subclass in isar-ref.pdf, to find out.It's not object-oriented classes, but then C++ doesn't compare to ML for functional programming
The nature of being exposed to languages, whether logic or programming, is you find out that none of them give you everything, and so you end up wanting everything that all of them give you separately.
You may be able to define objects in C++ easily, but try to define algebraic data types in C++.
You kind of can:
But it's not ridiculously easy like with Isabelle/HOL, which is similar to Haskell, and the pattern matching abilities of the workarounds I've tried is not even close.
But, hey, I'm all for the eventual convergence of all these things we want.