
On Mon, Jan 14, 2013 at 09:03:38PM +0200, Roman Cheplyaka wrote:
* Simon Peyton-Jones
[2013-01-14 18:09:50+0000] Friends
I'd like to propose a way to "promote" newtypes over their enclosing type. Here's the writeup http://hackage.haskell.org/trac/ghc/wiki/NewtypeWrappers
Any comments?
Why not just have a pseudo-function 'coerce'?
By pseudo-function I mean something that can be used anywhere (or almost anywhere?) where a function can, but is a keyword and doesn't have a type. (It'd be similar to ($) as implemented by GHC, I figure.)
The static semantics would be to compute the "inner" and "outer" types to the extent possible, and then behave as if the function was defined as a wrapper or unwrapper function for those types. In case when it is ambiguous, an error is issued, and the standard tricks can be used to refine the type (including annotation coerce itself with a type).
It would be even better if we implemented a syntax for type arguments. Then, if type application was written "f @ t", you would be able to (or perhaps required to) write coerce @ from_type @ to_type expr Thanks Ian