Tell me more ×
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It's 100% free, no registration required.

I've started reading Practical Foundations for Programming Languages and in the first chapter, the author mentions that ast's are associated with sorts. Intuitively, sorts are like types, but I'd like to know if they have a precise definition, and which is it. I'd be glad if some references are provided as well.

share|improve this question

migrated from cstheory.stackexchange.com May 2 at 14:41

3 Answers

It appears in chapter four that sorts are for syntax and types are for semantics.

The example syntax chart on page 40 deals with the sorts in the language L{num str}. Apparently sorts are categories in the syntax of the language.

In particular, "plus" has a sort, which is the syntactic category of its result. The sort of the operator "plus" is named "Exp". That represents the fact that syntactically, an invocation of the operator "plus" is an expression. An invocation of the operator "plus" can fill a position in an abstract syntax tree where an expression is permitted. That's what kind of construction a "plus" is. That's how it fits into the structure of a text that represents a program.

The type system on page 41 deals with the types in language L{num str}. The type of operator "plus", given that its operands have type "num", is "num". This judgment is a partial description of the semantics of operator "plus". That is, part of the meaning of the operator "plus" is the combining of two numbers to produce a number. This meaning distinguishes "plus" from other expressions.

Furthermore, there is a sort named "Typ" that contains the two types, "num" and "str".

share|improve this answer
Well, he uses it in this concept, but he doesn't define it clearly. I found the term "Many-sorted logic" which seems to me that sorts and types are really closed related concepts. I just wanted to know a clear definition for both. – rslima May 6 at 11:10
It's something to do with "pure type systems". I suspect we could consider the presentation in "Lambda Calculi with Types" to be conventional. But it's not concise. I haven't yet found a reference that provides clear, concise definitions of term, type, kind, and sort. – minopret May 6 at 16:02

It depends on what semantics we would take for types and sorts. -- However a brief - little informal - definitions could be - Sorts are classes of ASTs and types are classes of values.

share|improve this answer

This is all from memory - I have not looked at it for quite a while, and I do not have the book you mention.

There is actually much similarity between sorts for the abstact syntax and types as usually understood. But sorts are a formal syntactic concept. Then, AS trees are syntax too.

An AST may be seen as a term in a multisorted algebra, i.e. an algebra where operators are typed (to speak informally) and characterised by a signature specifying the sort of arguments (i.e. subtrees, subterms) and the sort of the resulting tree. Thus operators cannot be used to build arbitrary trees. Now formal algebras can receive interpretation, and then sorts would be interpreted as types, as domains of values. However, in the case of the AS of a programming language, the types corresponding to the sorts in a semantic interpretation are the domains used to describe this interpretation. They are not the types used by programmers writing programs with that language.

Things may sometimes be a bit more complicated in practice, because some forms of abstract syntax allow some operators to buid trees (expressions) that belong to several sorts (an informal way to look at it). For example there could be a sort for syntactic constructs that represent variables (assignable entities), and another for expressions. But any variable can be used as an expression, the converse being false.

Early papers on this, for programming languages, date back to the mid-seventies. The conceptualization at the time was intended for the production of syntax conscious (the word "directed" was then used) programming environments. Look for Mentor and Centaur in Europe and for Cornell Program Synthesizer in the USA. They were the first two system to actually use such concepts in a practical way. Many others were developped afterwards.

But abstract syntax predates these systems. The Lisp language (1958) had abstract syntax, which is no surprise as it was developed by a logician, and for the purpose of making programs that manipulate programs (see also ML and LCF ... that came later). But Lisp was not sorted : everything was syntactically a list and more refined structure was essentially semantics dependent. This lead some people to consider, somewhat incorrectly, that Lisp had no syntax.

I would think that multi-sorted algebras are older than that. But I do not really know.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.