[Haskell-cafe] Typeclass problem

Mark T.B. Carroll Mark.Carroll at Aetion.com
Thu Jul 29 13:45:20 EDT 2004


I have a little programme that doesn't compile:

	module Example where

	class (Show c, Ord c, Bounded c) => MyClass c

	showThings :: MyClass c => c -> (String, String)

	showThings x =
	    let foo = maxBound :: c
	     in (show x, show foo)

If I change that second-to-last line to,

	    let foo = max x maxBound

then it compiles. However, it's clearly silly to use "max" just to make
the type of the maxBound be the same type as the x. (I'm assuming that the
Ord and the Bounded instances of the type are sensibly consistent.)

What should I be writing if I want foo to be the maxBound applied to the
type that x is?

-- Mark


More information about the Haskell-Cafe mailing list