[Haskell-beginners] Problems defining a type with a multiplication function

Brent Yorgey byorgey at seas.upenn.edu
Wed Sep 9 17:50:46 EDT 2009


On Wed, Sep 09, 2009 at 09:51:34PM +0100, Amy de Buitléir wrote:
> 
> ----- Quaternion.hs -----
> data Quaternion = Quaternion Double Double Double Double
>                   deriving (Show)
> 
> (*) :: (Quaternion a) => a -> a -> a

Also, I should point out that the '(blah) => ...' syntax is only for
type *classes*; Quaternion is just a data type so it doesn't make
sense to use it in this way.  The type signature instead ought to just say

  (*) :: Quaternion -> Quaternion -> Quaternion

although as others have pointed out you will still get the error about
(*) being ambiguous.  You can either implement Num as others have
suggested, or just use a different name for quaternion multiplication,
such as, say, (*!).

-Brent


More information about the Beginners mailing list