|
Re: Begginer question: msg#00052lang.haskell.cafe
On 6 Jan 2005, at 01:37, Maurício wrote: import Complex; Couldn't match `Float' against `Complex Float' Can you help me finding what is wrong? Shouldn't "b" be converted to Complex Float and be summed to sqr_delta? Haskell will not automatically convert b from Float to Complex Float. The arguments of (+) should have the same type. One alternative is to use b :+ 0 instead of b. (and similarly for a). Another approach is to define a 'cast' function like: toComplex x = (fromRational.toRational) x :: Complex Float and then you can use toComplex b instead of b :+ 0. that's more characters to type, though... Note that sqr_delta isn't going to be defined as you expect, either. Since delta has type Float, sqrt delta has type Float. (And sqrt -1 :: Float is Not A Number). If you want to do it by hand this way, then you want: sqr_delta = if delta >= 0 then (sqrt delta) :+ 0 else 0 :+ (sqrt (-delta)) :: (Complex Float); If delta was itself already Complex, then sqrt would do the right thing automatically. Jules |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Initial (term) algebra for a state monad: 00052, Ashley Yakeley |
|---|---|
| Next by Date: | Re: Begginer question: 00052, Ketil Malde |
| Previous by Thread: | Begginer questioni: 00052, Maurício |
| Next by Thread: | Re: Begginer question: 00052, Ketil Malde |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |