[Haskell-cafe] convergence of functions of Complex variables

Jerzy Karczmarczuk karczma at info.unicaen.fr
Wed Dec 15 06:15:07 EST 2004


William Lee Irwin III wrote:

>>>This does not work as expected on Complex numbers due to some odd
>>>typechecking hassles apparently associated with abs. ...
>>>
>Ross Paterson wrote:
>  
>
>>abs :: Num a => a -> a, whereas you want something that returns a Double.
>>You could define
>>class Norm a where
>>        norm :: a -> Double
>>instance Norm Float where
>>        norm = realToFrac . abs
>>instance Norm Double where
>>        norm = abs
>>instance RealFloat a => Norm (Complex a) where
>>        norm = realToFrac . magnitude
>>and use norm instead of abs.
>>    
>>
>
>Thanks; this appears to do the trick for me. Something of this kind
>would be useful to have in the std. libraries, at least for me.
>  
>
Provided you work only with one type for norms, say, Double.
In general, the construction of, say Normed Vector Spaces with
any type for the ('carrier') elements, and any norm compatible
with the elements would require multi-parametric classes.
With dependencies, of course...
Since they are not *so* old, and the numerics in Haskell have
been frozen a long time ago, Haskell libraries from the math
point of view evolve slowly. But people are interested in that, and
the work will continue.

Jerzy Karczmarczuk



More information about the Haskell-Cafe mailing list