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.