[Haskell-cafe] Re: type classes

Cotton Seed cotton at alum.mit.edu
Thu Jul 3 08:15:31 EDT 2008

A number of operations -- like order above -- are conceptually
connected not to the elements but to the structures themselves.  Here
is the outline of a more complicated example.  I also have a vector
space class

class VectorSpaceTy a b | a - > b where
  dimension :: a -> Integer
  basis :: (Field c) => a -> [b c]

where `b' is a vector space over the field `c'.

Suppose I have a haskell function `f :: a c -> b c' representing a
linear transformation between (elements) of two vector spaces.  I can

transformationMatrix :: VectorSpaceTy ta a -> VectorSpaceTy tb b -> (a
c -> b c) -> Matrix c

to compute the matrix of the linear transformation.

Another alternative is something like ModuleBasis from the numeric prelude:

class (Module.C a v) => C a v where
    {- | basis of the module with respect to the scalar type,
         the result must be independent of argument,
'Prelude.undefined' should suffice. -}
    basis :: a -> [v]

To compute the basis (for type reasons?) basis needs an (ignored)
element of the vector space, but this seems ugly to me.

In my case, the vector space is the space of modular forms.  Computing
a basis requires a tremendous amount of work.  I only want to do it
once.  The ...Ty object gives me a place to stash the result.

How would you do this?


On Thu, Jul 3, 2008 at 7:01 AM, DavidA <davida at f2s.com> wrote:
> Slightly off-topic - but I'm curious to know why you want objects representing
> the structures as well as the elements - what will they be used for?
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list