
* Simon Peyton-Jones
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). I realise the implementation may be not as simple as it sounds to me... If the inference part is hard, then just always require a type annotation. Benefits: * very lightweight syntax, doesn't require additional declarations * anonymous (doesn't require making up a new name) * removes the strange distinction between wrap and unwrap (aren't the types equivalent anyway?) Roman