roma at ro-che.info
Mon Jan 14 20:03:38 CET 2013
* Simon Peyton-Jones <simonpj at microsoft.com> [2013-01-14 18:09:50+0000]
> I'd like to propose a way to "promote" newtypes over their enclosing type. Here's the writeup
> 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
* 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?)
More information about the Glasgow-haskell-users