[Haskell-cafe] Re: Generic types

Adde adde at trialcode.com
Tue Jun 14 03:02:35 EDT 2005


Cale Gibbard <cgibbard <at> gmail.com> writes:

> 
> Perhaps you want
> data UnitValue u n = 
>      (Unit u, Num n) => UnitValue {uUnit :: u, uValue :: n}
> 

I tried adding UnitValue as an instance of class Show, but I can't figure out
how to tell the compiler that u is a Unit and m is a Num (shouldn't it be able
to figure that out from the above declaration?):

instance Show (UnitValue u m) where
   show (UnitValue u m) = show m ++ (shortName u)

This is the error I'm getting:

    Could not deduce (Show m) from the context (Show (UnitValue u m))
      arising from use of `show' at /Users/adde/Projects/Haskell/units.hs:18:26-29
    Probable fix: add (Show m) to the class or instance method `show'
    In the first argument of `(++)', namely `show m'
    In the definition of `show': show (UnitValue u m) = (show m) ++ (shortName u)
    In the definition for method `show'

    Could not deduce (Unit u) from the context (Show (UnitValue u m))
      arising from use of `shortName' at
/Users/adde/Projects/Haskell/units.hs:18:37-45
    Probable fix: add (Unit u) to the class or instance method `show'
    In the second argument of `(++)', namely `(shortName u)'
    In the definition of `show': show (UnitValue u m) = (show m) ++ (shortName u)
    In the definition for method `show'





More information about the Haskell-Cafe mailing list