[mercury-users] Math Module

Nancy Mazur Nancy.Mazur at cs.kuleuven.ac.be
Mon Oct 21 19:05:48 AEST 2002


> >If you a moderate amount of maths at school, then you should
> >know that "e" and "pi" are well-known mathematical constants
> >which appear in common formulae.  For example, pythagorus's 
> >number
> >"pi" can be used for calculating the circumference or area of a 
> >circle,
> >given its radius.
> >
> >	:- 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'.

In your code you declare that you will implement a function known as
"circumference", yet there is no implementation. That is also exactly
what the error message states: no clauses for function "circumference". 

> 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.

You say it produces the same error? Strange. 
Your expression "NumRound(Num) = ..." is odd. In Mercury variables are
start with capital characters. Why NumRound(Num)? Why not simply
NumRound?

Have fun, 
Nancy
--------------------------------------------------------------------------
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