Re: Who needs types if we have terms?
- From: "tmp123" <tmp123@xxxxxxxxx>
- Date: 25 May 2005 10:43:33 -0700
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.
.
- Follow-Ups:
- Re: Who needs types if we have terms?
- From: Brian Hulley
- Re: Who needs types if we have terms?
- References:
- Who needs types if we have terms?
- From: tmp123
- Re: Who needs types if we have terms?
- From: Brian Hulley
- Who needs types if we have terms?
- Prev by Date: Re: newbie: Out of local stack, matching values from 0 to 10
- Next by Date: Re: Who needs types if we have terms?
- Previous by thread: Re: Who needs types if we have terms?
- Next by thread: Re: Who needs types if we have terms?
- Index(es):