Re: Who needs types if we have terms?



Brian Hulley wrote:
>
> 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
>


Hi,

Thanks for the explanation. Also to Mr.Torkel Franzen. I'm trying to
clarify some concepts that I use in the day to day, but without a good
theorical basis.

I'm wondering me what is better:

result(plus(Exp1, Exp2), Y) :- ...
result(number(plus(Exp1, Exp2)), Y) :- ...
result(number(plus(number(Exp1), number(Exp2))), Y) :- ...

or even:

result(number(plus(Exp1, Exp2)), number(Y)) :- ...

Comments, or reference pointers are welcome.

Thanks again.

.