Re: Who needs types if we have terms?



tmp123 wrote:
> Or, in other words, is a term a data type?. They are usually used like
> data types?
> Because I've read a lot of post about prolog typed/untyped, but I'm
> wondering me if the only diference is in type (term) checking.

Prolog terms are often used as constructors for elements of a type.
This is not the same thing as the type itself. For example, elements of
the type "arithmetic expression" could be numbers, the operator "plus"
applied to two arithmetic expressions etc.

In this example, the two constructors of the arithmetic_expression type
could be number(X) for some number X and plus(Exp1, Exp2) for some
arithmetic_expression Exp1 and Exp2 as used in:

%result(+Exp, -Value)

result(number(X),X).
result(plus(Exp1, Exp2), Y) :-
result(Exp1, R1),
result(Exp2, R2),
Y is R1 + R2.

So languages which allow you to define types would allow you to specify
that the first argument of result/2 has type "arithmetic_expression" ie
is limited to any term constructed using number/1 and/or plus/2

Regards, Brian.

.