Re: [Haskell-cafe] convergence of functions of Complex variables

2004-12-15 Thread Henning Thielemann

On Wed, 15 Dec 2004, William Lee Irwin III wrote:

> On Wed, Dec 15, 2004 at 10:28:18AM +, 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.

http://cvs.haskell.org/darcs/numericprelude/physunit/Normalization.hs

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] convergence of functions of Complex variables

2004-12-15 Thread Jerzy Karczmarczuk
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
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] convergence of functions of Complex variables

2004-12-15 Thread William Lee Irwin III
On Wed, Dec 15, 2004 at 02:07:10AM -0800, William Lee Irwin III wrote:
>> This does not work as expected on Complex numbers due to some odd
>> typechecking hassles apparently associated with abs. How do I get this
>> to typecheck for both real (e.g. Double) and Complex arguments?

On Wed, Dec 15, 2004 at 10:28:18AM +, 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.


-- wli
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] convergence of functions of Complex variables

2004-12-15 Thread Ross Paterson
On Wed, Dec 15, 2004 at 02:07:10AM -0800, William Lee Irwin III wrote:
> This does not work as expected on Complex numbers due to some odd
> typechecking hassles apparently associated with abs. How do I get this
> to typecheck for both real (e.g. Double) and Complex arguments?

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.
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe