purescript-newtype
purescript-newtype copied to clipboard
Provide cheap coercions over functors
Something like
unwrapF :: forall f a b. (Functor f, Newtype a b) => f a -> f b
unwrapF = unsafeCoerce
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!
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
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
I think this needs more discussion now that we have coerce.