A simple problem

William Lee Irwin III wli@holomorphy.com
Thu, 18 Jan 2001 15:57:46 -0800

Moving over to haskell-cafe...

At 2001-01-18 05:16, Saswat Anand wrote:
>> fun 3  --gives error in Hugs
>> fun (3::Integer) -- OK
>> I am a building an embedded language, so don't want user to cast. Is
>> there a solution?

On Thu, Jan 18, 2001 at 03:38:10PM -0800, Ashley Yakeley wrote:
> 3 is not always an Integer. It's of type "(Num a) => a".
> I couldn't find a way to say that every Num is a C.

I didn't try to say every Num is C, but I found a way to make his
example work:

class C a where
	fun :: a -> Integer

instance Integral a => C a where
	fun = toInteger . succ

One has no trouble whatsoever with evaluating fun 3 with this instance
defined instead of the original. I'm not sure as to the details, as I'm
fuzzy on the typing derivations making heavy use of qualified types. Is
this the monomorphism restriction biting us again?

<nrut> how does one decide if something is undecidable?
<Galois> carefully