[Haskell-cafe] closed classes [was: Re: exceptions vs. Either]

André Pang ozone at algorithm.com.au
Thu Aug 12 09:52:29 EDT 2004


On 12/08/2004, at 11:05 PM, Simon Peyton-Jones 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 Haskell-Cafe mailing list