-
Notifications
You must be signed in to change notification settings - Fork 13
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
Choice #110
base: master
Are you sure you want to change the base?
Choice #110
Conversation
Since Choice relies on List (and we could conceivably define one using Assignment as well), it makes sense for this to be a part of the same module.
Hi @benjaminselfridge. I think there's a slightly different tack we could take here as well. In this PR, we express type Choice :: (k -> Type) -> [k] -> Type
data Choice f as
where
Here :: f x -> Choice f (x ': xs)
There :: Choice f xs -> Choice f (x ': xs) and then we can recover type Index xs x = Choice ((:~:) x) xs The benefit is that many operations for We can go further, in fact. In particular, there is an involutive relationship between n-ary products and n-ary coproducts. So we can write the following newtype: type Summary :: Type -> (k -> Type) -> k -> Type
newtype Summary r f i = Summary { summarize :: f i -> r }
type Co :: ((k -> Type) -> [k] -> Type) -> (k -> Type) -> [k] -> Type
newtype Co p f as = Co { runCo :: forall r. p (Summary r f) as -> r } and a fun result is that |
I found a use for this; it's a sum type to
List
's product.Don't know if it should be in a separate module, like
Data.Choice.List
orData.List.Choice
(since it relies onData.List
, and we might want to make another version that usesAssignment
s at some point).Not sure if it needs to be in
parameterized-utils
at all, but it would seem strange to omit it, since it is dual toList
.This should not be merged until the
ShowF
type synonym change is merged; this kind of relies on that. I think the only way to derive aShow
instance for this data type is using quantified constraints (otherwise we'd have to doShowF f => Show (Choice f tps)
, which I don't think is derivable since you have to useshowF
instead ofshow
).