Newtype wrappers in hsSyn
Simon Marlow
marlowsd at gmail.com
Thu Jan 28 05:28:56 EST 2010
On 28/01/2010 00:26, Simon Peyton-Jones wrote:
> |> type PostTcType = Maybe Type
> |>
> |> Now you're representing the data that isn't there by a Nothing, rather
> |> than a _|_. You could even newtype it and have fromPostTcType be
> |> equivalent to fromJust with a helpful error about the ordering. It
> |> will be slower than what's currently there, but also more accurate
> |> statement of intent.
> |
> | Yes, I don't know why it is implemented this way. Probably to avoid an
> | indirection and the memory overhead. Could be worth measuring.
>
> It's just that I didn't want to unwrap a Just that I knew was a Just! An error thunk seemed just right. Using a newtype would do fine.
Right, there doesn't seem much point in using a Maybe if every time you
examine it the Nothing branch would call error.
Encoding the information in the types would be better of course (as in
Ian's suggestion), if that were doable.
Cheers,
Simon
More information about the Cvs-ghc
mailing list