| some time ago, it was pointed out that generalized newtype deriving could be
| used to circumvent module borders. Now, I found out that generalized newtype
| deriving can even be used to define functions that would be impossible to 
define
| otherwise. To me, this is surprising since I thought that generalized newtype
| deriving was only intended to save the programmer from writing boilerplate
| code, not to extend expressiveness.

Yes indeed.  See http://hackage.haskell.org/trac/ghc/ticket/1496 for why this 
is really a bug in general. 

The trouble described there really happens when 'item' (in your iso class) in 
instantiated to a data type with a constructor whose fields use type functions.

Stephanie Weirich, Steve Zdancewic, Dimitrios Vytiniotis and I have been 
working hard on a development of the FC intermediate language, and hence of the 
source language, that will close this (embarrassing) loophole, and allow some 
new expressiveness.  Nothing written down in a form that someone other than us 
can make sense of, but there will be!  In brief, though, we're going to end up 
with kinds looking like
        * => *
as well as the existing
        * -> *
The new form means "a type-indexed function" whereas the latter means "a 
type-parametric function". 

John Meacham's example is also very interesting. Even if the data type doesn't 
use type functions, it might have invariants concerning type classes (his 
example is Set), and converting all the elements might destroy the invariants.  
Excellent point!  There's no type-soundness issue (no run-time seg fault) but 
something nearly as bad.  Will have to think about that.  Probably declaring 
Set to have kind (* => *) will do the job.

Thanks for the thread.

Simon
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to