-
I'm coming from Haskell where I have a type constructor
I'd like to define the same structure in CUE:
but I haven't found a way to define that |
Beta Was this translation helpful? Give feedback.
Answered by
myitcv
Jan 2, 2025
Replies: 1 comment
-
I think you achieve what you want by making the ! exec cue export x.cue
cmp stderr stderr.golden
exec cue export y.cue
cmp stdout stdout.golden
-- x.cue --
#FinDefSet: {
_#Type!: _
AllBut: [..._#Type]
} | {
_#Type!: _
Only: [..._#Type]
}
value: #FinDefSet & {_#Type: int}
value: Only: [1, 2, 3]
notAllowed: #FinDefSet
notAllowed: Only: []
-- y.cue --
#FinDefSet: {
_#Type!: _
AllBut: [..._#Type]
} | {
_#Type!: _
Only: [..._#Type]
}
value: #FinDefSet & {_#Type: int}
value: Only: [1, 2, 3]
notAllowed: #FinDefSet & {_#Type: string}
notAllowed: Only: []
-- stderr.golden --
notAllowed._#Type: field is required but not present:
./x.cue:5:2
./x.cue:12:13
-- stdout.golden --
{
"value": {
"Only": [
1,
2,
3
]
},
"notAllowed": {
"Only": []
}
} Whether you want to allow empty lists is separate, but easily fixed from this point. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
loisch
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you achieve what you want by making the
_#Type
"parameter" required: