Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapExists helper #16

Open
prescientmoon opened this issue Aug 7, 2021 · 2 comments · May be fixed by #19
Open

mapExists helper #16

prescientmoon opened this issue Aug 7, 2021 · 2 comments · May be fixed by #19
Labels
status: needs more info This issue needs more info before any action can be done.

Comments

@prescientmoon
Copy link

I found myself implementing a very basic mapExists function for my latest project, and wondered if it might fit here:

-- | Map the interoior of an existential
mapExists :: forall f. (forall a. f a -> f a) -> Exists f -> Exists f
mapExists f = runExists (f >>> mkExists)

I have not tried, but unsafeCoerce identity should work as well.

@JordanMartinez JordanMartinez added the status: needs more info This issue needs more info before any action can be done. label Dec 4, 2021
@yukikurage
Copy link

yukikurage commented Nov 6, 2022

mapExists can also change type.

mapExists :: forall f g. (f ~> g) -> Exists f -> Exists g
mapExists f = runExists (mkExists <<< f)

This may be a little useful when making a Functor instance of the data created by Exists

data T a b = T b (b -> a)

newtype TE a = TE (Exists (T a))

instance Functor TE where
  map f (TE e) = TE $ mapExists (\(T a g) -> T a (map f g)) e
  --  map f (TE e) = TE $ runExists (\(T a g) -> mkExists $ T a (map f g)) e

It is just a little different, but I think we can write more intuitively.

@JordanMartinez
Copy link
Contributor

Works for me.

@yukikurage yukikurage linked a pull request Nov 16, 2022 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs more info This issue needs more info before any action can be done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants