[Haskellcafe] closed classes [was: Re: exceptions vs. Either]
Simon PeytonJones
simonpj at microsoft.com
Thu Aug 12 10:08:32 EDT 2004
but if f is exported, that's probably not what you want. And if you give a type sig to f,
f:: forall a. C a => a > Maybe a
the type sig will say it's polymorphic, while the improvement rule will say that a must be Int.
Simon
 Original Message
 From: André Pang [mailto:ozone at algorithm.com.au]
 Sent: 12 August 2004 14:52
 To: Simon PeytonJones
 Cc: MR K P SCHUPKE; haskellcafe at haskell.org; qrczak at knm.org.pl
 Subject: Re: [Haskellcafe] closed classes [was: Re: exceptions vs. Either]

 On 12/08/2004, at 11:05 PM, Simon PeytonJones wrote:

 > module M where
 >
 > class C a where
 > op :: a > a
 >
 > instance C Int where
 > op x = x+1
 >
 > f x = Just (op x)
 >
 > Under your proposal, I'd infer f :: Int > Maybe Int, on the grounds
 > that C is closed and there is only one instance.

 If I'm reading Keean's posts right, that's exactly his point: if you
 only have one instance of class C, then it's valid to improve f's type
 to :: Int > Maybe Int, right?

 If, on the other hand, you had another instance (e.g. instance C Bool),
 then the signature of f would have to remain polymorphic.


 
 % Andre Pang : trust.in.love.to.save
More information about the HaskellCafe
mailing list