[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-cafe
Subject:    Re: [Haskell-cafe] tricky recursive type instance method
From:       Henning Thielemann <schlepptop () henning-thielemann ! de>
Date:       2011-01-29 20:50:21
Message-ID: 4D447D8D.8070601 () henning-thielemann ! de
[Download RAW message or body]

Frank Kuehnel schrieb:
> Hi folks,
> 
> how do I make this work: I want a division algebra over a field k, and I want to \
> define the conjugation of complex numbers, i.e. conj (C 1 2) but also the \
> conjugation of tensors of complex numbers conj (C (C 1 2) (C 1 4))
> 
> ghci load that stuff butt barfs on a simple
> > conj (C 1 2)
> 
> with 
> instance Real a => DAlgebra a a -- Defined at Clifford.hs:20:10-31
> instance (Real r, Num a, DAlgebra a r) => DAlgebra (Complex a) r
> 
> 
> here's the code:
> 
> -- for a normed division algebra we need a norm and conjugation!
> class DAlgebra a k | a -> k where -- need functional dependence because conj \
> doesn't refer to k conj :: a -> a

Since conj does not need type 'k' I would separate it from class DAlgebra.

> abs2 :: a -> k
> 
> -- real numbers are a division algebra
> instance Real a => DAlgebra a a where
> conj    = id
> abs2 x  = x*x
> 
> -- Complex numbers form a normed commutative division algebra
> data Complex a = C a a deriving (Eq,Show)

This is the way, we defined Complex in NumericPrelude. We have no
RealFloat constraint there in order to allow Gaussian numbers and other
types.


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic