purescript-newtype icon indicating copy to clipboard operation
purescript-newtype copied to clipboard

Provide cheap coercions over functors

Open natefaubion opened this issue 9 years ago • 4 comments

Something like

unwrapF :: forall f a b. (Functor f, Newtype a b) => f a -> f b
unwrapF = unsafeCoerce

natefaubion avatar Jan 23 '17 23:01 natefaubion

I just came to open this same issue :d

I was thinking on this too while looking at https://github.com/purescript/purescript-strings/pull/100/commits/2b5cae787fc1c8329f8dc7334a51f0b2f2345a7b#diff-5612745fec556dc34848a6dcc331678fR457.

And seems to be definitely useful!

safareli avatar Feb 12 '18 11:02 safareli

How about utilities for wrap and it's variations as well? Seems useful:

wrapF :: forall f t a. Newtype t a => f a -> f t
wrapF = unsafeCoerce

wrapF' :: forall f g t a. Newtype t a => f (g a) -> f (g t)
wrapF' = unsafeCoerce

wrapFst :: forall f t a x. Newtype t a => f a x -> f t x
wrapFst = unsafeCoerce

jvliwanag avatar Feb 27 '19 06:02 jvliwanag

I think adding wrapF would be a good idea but imho others might be a bit too much. Also there is open PR #15 feel free to comment there too

safareli avatar Feb 27 '19 12:02 safareli

I think this needs more discussion now that we have coerce.

JordanMartinez avatar Dec 04 '21 15:12 JordanMartinez