So far I was able to stick with standard Haskell 98
features in the module QuantumVector I am working on.
But now it seems to me that I do not have any other choice
but to use Mark's extension of multiple parameter
classes.
The problem I have is described below.
Question: Is there any way to code it in Haskell 98?
Question: If not, how portable is Mark's extension?
Do I need to use it at all?
Jan
===================================================
The problem is rather simple. I have two different
kinds of vectors: Ket a and Bra a and two conversion
functions "toBra" and "toKet".
I also define linear operators, which can be
either of the form:
a :: (Ord a, Ord b) => Ket a -> Ket b
or
b :: (Ord a, Ord b) => Bra a -> Bra b
These functions produce the adjoint operators:
toBra . a . toKet :: Bra a -> Bra b
toKet . b . toBra :: Ket a -> Ket b
But I want to define a function adjoint, such
that:
(adjoint . adjoint) a == a, or
(adjoint . adjoint) b == b
I defined it this way:
adjoint op = dual . op . dual
class Dual a b | a -> b; b -> a where
dual :: a -> b
instance (Ord a, Ord b) => Dual (Bra a) (Ket b) where
dual = toKet
instance (Ord a, Ord b) => Dual (Ket a) (Bra b) where
dual = toBra
It all works perfectly well in Hugs -98 extension, but I am
afraid I am losing some portability here.