IssueRaiser

It's not necessarily unsafe, but it is very difficult to do safely.

It's not necessarily unsafe, but it is very difficult to do safely. The design suggested is certainly unsafe, however---there's no way to ensure that the values don't lie about their self-reported type and so using that to trigger a coercion is liable to explore things. If the compiler provides a couple things: data TypeRepr typeReprEq :: TypeRepr -> TypeRepr -> Bool typeOf :: Typeable a => a -> TypeRepr such that TypeRepr cannot be generated (e.g. faked) by users, typeOf is guaranteed to be genuine, and (this is the hardest) such a thing doesn't violate parametricity then you can use that interface to write safeCoerce :: (Typeable a, Typeable b) => a -> Maybe b which is guaranteed to only allow the coercion when `a` and `b` actually happen to be the same type.

Posted by tel on Apr 17, 2015, 12:35 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.7,000 issues0 comments

ux (Software)

It's not necessarily unsafe, but it is very difficult to do safely.

telApr 17, 2015, 12:35 PM

It's not necessarily unsafe, but it is very difficult to do safely. The design suggested is certainly unsafe, however---there's no way to ensure that the values don't lie about their self-reported type and so using that to trigger a coercion is liable to explore things. If the compiler provides a couple things: data TypeRepr typeReprEq :: TypeRepr -> TypeRepr -> Bool typeOf :: Typeable a => a -> TypeRepr such that TypeRepr cannot be generated (e.g. faked) by users, typeOf is guaranteed to be genuine, and (this is the hardest) such a thing doesn't violate parametricity then you can use that interface to write safeCoerce :: (Typeable a, Typeable b) => a -> Maybe b which is guaranteed to only allow the coercion when `a` and `b` actually happen to be the same type.

Comments (0)

No comments yet. Start the discussion.

Comment on this issue