[mercury-users] Math Module

Gustavo A. Ospina gos at info.ucl.ac.be
Mon Oct 21 19:19:31 AEST 2002


Hello,

> >       :- func area(float) = float.
> >       area(Radius) = math__pi * Radius * Radius.
> >
> >       :- func circumference(float) = float.
> >       circumference(Radius) = 2.0 * math__pi * Radius.
> Thanks
> 
> I have tried using them in a code, but now I get one error. Plz do
> help me rectify it. The code is below and with the error...
> 
> Code
> :- module 'Nex_int'.
> 
> :- interface.
> :- import_module io.
> :- pred main(io__state, io__state).
> :- mode main(di, uo) is det.
> 
> :- implementation.
> :- import_module math, float.
> :- func circumference(float) = float.
>   :- mode circumference(in) = out is det.
> main --> { Radius = 10.0, circumference(Radius) = 2.0 * math__pi *
> Radius}.
> 
> The error is ...
> Nex_int.m:010: Error: no clauses for function
> `Nex_int:circumference/1'.
> 
> Similarly I do have some more queries...
> 
> 1) I have tried using math__round but I do get the same error as
> above. That piece of code is below:
> main --> { Num = 10.5, NumRound(Num) = math__round(Num) }.
> Plz do suggest a solution.

Have you tried to insert the code (the clauses) of the functions 'area'
and 'circunference' into the text of your module? The error is there.

You have another error. Instead of

NumRound(Num) = math__round(Num)

You should write

NumRound = math__round(Num)

If you intend to instantiate a new variable (logically dependent of Num
by the meaning of math__round).

> 2) I would like to know how do I use math__ceiling, math__floor
> and math__truncate? It is a bit confusing as to how to apply the
> logic for writng the code.

You use that in the same way than in your example, instantiating logic
variables or comparing values, like in

math__ceiling(Num) = math__round(Num)

But before you try that, I suggest you to try some more simple examples
like the yours.

Regards,

+ Gustavo +
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list