when discussing void on haskell libraries mailing list, there this remark:
back in day used implemented
unsafecoerce@ behest of conor mcbride didn't want pay traversing wholefunctor, replacing contents, when types tell shouldn't have any. correct if applied proper functor, subvertible in presence of gadts.
the documentation unsafevacuous says:
if
voiduninhabitedfunctorholds values of typevoidholding no values.this safe valid functors not perform gadt-like analysis on argument.
how such mischievous gadt functor instance like? (using total functions of course, without undefined, error etc.)
it's possible if you're willing give functor instance not adhere functor laws (but total):
{-# language gadts, kindsignatures #-} import data.void import data.void.unsafe data f :: * -> * c :: f void d :: f instance functor f fmap f _ = d wrong :: () wrong = case (unsafevacuous c :: f int) of d -> () now evaluating wrong results in run-time exception, though type-checker considers total.
edit
because there's been discussion functoriality, let me add informal argument why gadt performs analysis on argument cannot functor. if have
data f :: * -> * c :: ... -> f ... where something type isn't plain variable, cannot give valid functor instance f. fmap function have map c c in order adhere identity law functors. have produce f b, unknown b. if something plain variable, isn't possible.
Comments
Post a Comment