Skip to content
This repository has been archived by the owner on Dec 17, 2020. It is now read-only.

Functor/Foldable/Traversable/Applicative instances for Union? #42

Open
spacekitteh opened this issue May 23, 2017 · 0 comments
Open

Functor/Foldable/Traversable/Applicative instances for Union? #42

spacekitteh opened this issue May 23, 2017 · 0 comments

Comments

@spacekitteh
Copy link

It would be amazing if you could provide instances of these classes for Data.OpenUnion. Here's how I implemented Functor:

type family ConstrainedMembers constr l = (r :: Constraint) where
  ConstrainedMembers constr (t ': c) = (constr t, ConstrainedMembers constr c)
  ConstrainedMembers constr '[] = ()

instance {-#OVERLAPPING#-} Functor (Union '[]) where
  fmap f a = error "Absurd?"
instance {-#OVERLAPPING#-} (ConstrainedMembers Functor f, r ~ (h : tail), Functor (Union tail)) => Functor (Union r) where
  fmap f a = case decomp a of
                       Right t -> inj (fmap f t)
                       Left remainder -> weaken (fmap f remainder)

As you can see, it's pretty ugly and it took quite a while to get everything just right. I'm scared of doing the rest!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant