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

Simon Peyton-Jones simonpj at microsoft.com
Thu Aug 12 09:05:41 EDT 2004

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.


| -----Original Message-----
| From: haskell-cafe-bounces at haskell.org
[mailto:haskell-cafe-bounces at haskell.org] On Behalf Of MR
| Sent: 12 August 2004 14:03
| To: haskell-cafe at haskell.org; qrczak at knm.org.pl
| Subject: Re: [Haskell-cafe] closed classes [was: Re: exceptions vs.
| Okay anybody whish to argue against these points:
| 	1) closed or open is the same if no instances overlap
| 	2) overlapping instances (open or closed) can break
| 	   code in modules which import the defining module
| 	   if a new instance is declared in any imported
| 	   module.
| 	3) code changes in non-imported modules cannot have
| 	   any affect on _this_ module. (And here I count
| 	   any module in the import tree as imported - at
| 	   least in terms of recompilation dependancies)
| The conclusion appears to be it is overlapping instances
| that cause code to be 'breakable' by simply defining a new
| instance and not closing the class. Closing the class
| would appear to have no adverse affects on existing
| programs (as it allows better improvement rules) all existing
| programs that compile without the better improvement rules
| should still compile - just a few more programs will be
| valid with the closed assumption?
| 	Keean.
| _______________________________________________
| Haskell-Cafe mailing list
| Haskell-Cafe at haskell.org
| http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list