Write a function makePol that takes two real numbers r and v and returns a complex number in polar form. The Function is supposed to only handle values between -2pi and 2pi. For other values on v there should be an error. For negative v it should use positive angle, like v+2pi.
English is not my first language so sorry if I translated it a bit weird.
Oh, sorry. Figured youād need all info in order to help me.
Iāve tried;
makePol :: Float ā Float ā Cplex
makePol r v
| v > 2pi = error āV is not in intervalā
| v < (-2)pi = error āv is not in intervalā
| v < 0 = (āPā,r(cos (v+2pi)),r*(sin (v+2pi)))
| otherwise = (āPā,r(cos v),r*(sin v))
But Iām unsure wether or not it is correct to use guards in my case or if I used them correctly.
Oh sorry, only posted the things I thought were useful for this assignment. Hereās my full āmoduleā
type Cplex = (String,Float,Float)
makeRec :: Float ā Float ā Cplex
makeRec a b = (āRā,a,b)
makePol :: Float ā Float ā Cplex
makePol r v
| v > 2pi = error āv is not in intervalā
| v < (-2)pi = error āv is not in intervalā
| v < 0 = (āPā,r(cos (v+2pi)),r*(sin (v+2pi)))
| otherwise = (āPā,r(cos v),r*(sin v))
type Cplex = (String,Float,Float)
makeRec :: Float -> Float -> Cplex
makeRec a b = ("R",a,b)
makePol :: Float -> Float -> Cplex
makePol r v
| v > 2pi = error "v is not in interval"
| v < (-2)pi = error "v is not in interval"
| v < 0 = ("P",r(cos (v+2pi)),r*(sin (v+2pi)))
| otherwise = ("P",r(cos v),r*(sin v))
Here it is properly idented and without Unicode. First error GHC throws at me is:
prova.hs:10:20: error:
ā¢ Couldn't match expected type āFloat -> Floatā
with actual type āFloatā
ā¢ The function ārā is applied to one value argument,
but its type āFloatā has none
In the expression: r (cos (v + 2 pi))
In the expression: ("P", r (cos (v + 2 pi)), r * (sin (v + 2 pi)))
|
10 | | v < 0 = ("P",r(cos (v+2pi)),r*(sin (v+2pi)))
| ^^^^^^^^^^^^^^
And indeed r is a Float. So what are you trying to do with r(cos (v+2pi))? @minimoll you need to learn how to heed the compiler and simple exercises like these will become a breeze.