-
-
Notifications
You must be signed in to change notification settings - Fork 179
Proposal: Allow combining union types #175
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
Comments
@aleator: Yeah, this seems reasonable to me. My only suggestion is to use |
What happens on a conflict between two variants with differing types? EDIT: oh, I see - the second on is chosen - it's shown in the initial example as |
One thing that bothers me about using ⩔ is that it wouldn't behave exactly like ⩓, and more like //. I don't see how recursively updating unions would make sense. I might be wrong at this though. Regarding the name, there isn't a type level If you'd like, I could take a stab at implementing this. |
Just for sake of procrastination, here is a stab at getting the semantics done (confessing that I actually haven't read the dhall semantics before doing this). Since naming is hard, I used the 'plus-in-a-circle' as a stand in.
|
@aleator: Yeah, I like the idea of a type-level analog for |
Based on issue dhall-lang#175 This is a draft and I haven't yet read the semantics.md through, so it might be complete nonsense.
This was initially mentioned in issue dhall-lang#175.
Would definitely be cool to have this feature available ! |
Just hit this limitation again with dhall-kubernetes. I want to use cert-manager which defines custom resources. I can normally define dhall types for them and use them, but in order to tie everything together I have one file per service that is a list of the big kubernetes union. The problem: I can't add the cert-manager types to that union without copy+pasting the file from dhall-kubernetes to my own repository. With a union operator, I could simply change my top level union import file from: let union =
https://raw.githubusercontent.com/dhall-lang/dhall-kubernetes/master/typesUnion.dhall sha256:8e8db456b218b93f8241d497e54d07214b132523fe84263e6c03496c141a8b18
in union to let union =
https://raw.githubusercontent.com/dhall-lang/dhall-kubernetes/master/typesUnion.dhall sha256:8e8db456b218b93f8241d497e54d07214b132523fe84263e6c03496c141a8b18
let cert-union = ./cert-manager/union.dhall
in union \\// cert-union |
@jvanbruegge I think this proposal mostly needs a volunteer to standardize it. Would you be interested in being that volunteer? |
Sadly not at the moment, as my spare time is quite limited right now. Most likely not before April |
I think we should narrow down this proposal to just standardizing support for This came up recently again in: https://discourse.dhall-lang.org/t/sum-type-subsets/219 |
Didn't we say |
@Nadrieril: There are two reasons I think it would be simpler to standardize
|
@Gabriel439 So we'd standardize only |
@Nadrieril: I think the natural "dual" behavior for
|
Ah right, what I mentioned looks more like a dual to record projection I guess. |
@Nadrieril: Yes, any operator for unions can be implemented in terms of its dual operation on records. Also, to be pedantic, you would implement In fact, the converse is also true: you can implement any operator on records in terms of its dual operation on unions. This means that you could implement the behavior of This redundancy is a natural consequence of the fact that unions can be encoded in terms of functions on records: -- Edit: Fixed the type as @Nadrieril noted
< A₀ : T₀ | A₁ : T₁ | … > ≅ forall (r : Type) → { A₀ : T₀ → r, A₁ : T₁ → r, … } → r ... and, dually, you can implement records in terms of functions on unions: -- Edit: Fixed the type
{ A₀ : T₀, A₁ : T₁, … } ≅ forall (r : Type) → < A₀ : T₀ → r, A₁ : T₁ → r, … } → r ... so any time you add keyword or operator on unions or records you make its dual keyword or operator redundant. In fact, this duality implies that there is a missing keyword that is the dual of |
@Gabriel439 Oh neat, I never realized you could go both ways between records and unions. That makes Note: you have an extra
and
I thought about it, but then since the records being merged are records of functions, |
I think this could be really really useful. A potential usecase for this, that I'm currently facing, is related to I'm tying to output custom resource types (defined for example by CRDs) into Kubernetes Lists, together with standard Kubernetes Types and to do that I need to have all of them into a single Union. The only way I can think of for achieving it, is to create a superset of the Kubernetes TypesUnion that extends it with the desired custom types, by copy/pasting the two Types groups into a new Union or to use a modified version of @TristanCacqueray's mini-generate to achieve the same in a more automated way (if you have better ideas here, suggestions are more than welcome). I think having |
@jvanbruegge and @damdo I just created dhall-lang/dhall-kubernetes#187 for exactly this issue (before seeing your comment here) Did either of you come up with a solution for this when using dhall-kubernetes? |
This updates the `dhall-format` tutorial example to reflect the improvements introduced in 8d27f8c
Would it be possible to have an analogue of // for union types? As in, <a:T1 | b:T2 | c:T3> \/ <a:T2 | d:T4 | e:T5> = <a:T2 | b:T2 | c:T3 | d:T4 | e:T5>
The use case I have is something like this
The text was updated successfully, but these errors were encountered: