mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
Rename variant_var to tag_union_var
This commit is contained in:
parent
c81eecd644
commit
7e12bcff1d
8 changed files with 53 additions and 33 deletions
|
@ -2261,13 +2261,13 @@ pub struct LambdaSet {
|
|||
///
|
||||
/// ```text
|
||||
/// XEffect : A -> B
|
||||
///
|
||||
///
|
||||
/// after : ({} -> XEffect) -> XEffect
|
||||
/// after =
|
||||
/// \cont ->
|
||||
/// f = \A -[`f (typeof cont)]-> when cont {} is A -> B
|
||||
/// f
|
||||
///
|
||||
///
|
||||
/// nestForever : {} -> XEffect
|
||||
/// nestForever = \{} -[`nestForever]-> after nestForever
|
||||
/// ^^^^^^^^^^^ {} -[`nestForever]-> A -[`f ({} -[`nestForever]-> A -[`f ...]-> B)]-> B
|
||||
|
@ -2485,6 +2485,26 @@ pub trait Label: Sized + Clone {
|
|||
pub type UnionTags = UnionLabels<TagName>;
|
||||
pub type UnionLambdas = UnionLabels<Symbol>;
|
||||
|
||||
impl UnionTags {
|
||||
pub fn for_result(subs: &mut Subs, ok_payload: Variable, err_payload: Variable) -> Self {
|
||||
let ok_tuple = {
|
||||
let variables_slice = VariableSubsSlice::reserve_into_subs(subs, 1);
|
||||
VariableSubsSlice::insert_into_subs(subs, std::iter::once(ok_payload));
|
||||
|
||||
("Ok".into(), variables_slice)
|
||||
};
|
||||
|
||||
let err_tuple = {
|
||||
let variables_slice = VariableSubsSlice::reserve_into_subs(subs, 1);
|
||||
VariableSubsSlice::insert_into_subs(subs, std::iter::once(err_payload));
|
||||
|
||||
("Err".into(), variables_slice)
|
||||
};
|
||||
|
||||
UnionTags::insert_slices_into_subs(subs, [err_tuple, ok_tuple])
|
||||
}
|
||||
}
|
||||
|
||||
impl Label for TagName {
|
||||
fn index_subs(subs: &Subs, idx: SubsIndex<Self>) -> &Self {
|
||||
&subs[idx]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue