diff --git a/compiler/builtins/src/unique.rs b/compiler/builtins/src/unique.rs index 12e3ccfa56..057a719a06 100644 --- a/compiler/builtins/src/unique.rs +++ b/compiler/builtins/src/unique.rs @@ -57,8 +57,11 @@ impl IDStore { } } -fn shared() -> SolvedType { - SolvedType::Boolean(SolvedAtom::Zero, vec![]) +fn shared(base: SolvedType) -> SolvedType { + SolvedType::Apply( + Symbol::ATTR_ATTR, + vec![SolvedType::Boolean(SolvedAtom::Zero, vec![]), base], + ) } fn boolean(b: VarId) -> SolvedType { @@ -644,21 +647,23 @@ pub fn types() -> MutMap { ) }); + // To repeat an item, it must be shared! + // // repeat : Attr * Int - // , a - // -> Attr * (List a) + // , Attr Shared a + // -> Attr * (List (Attr Shared a)) add_type(Symbol::LIST_REPEAT, { let a = tvar!(); let star1 = tvar!(); let star2 = tvar!(); unique_function( - vec![int_type(star1), flex(a)], + vec![int_type(star1), shared(flex(a))], SolvedType::Apply( Symbol::ATTR_ATTR, vec![ boolean(star2), - SolvedType::Apply(Symbol::LIST_LIST, vec![flex(a)]), + SolvedType::Apply(Symbol::LIST_LIST, vec![shared(flex(a))]), ], ), ) @@ -714,13 +719,7 @@ pub fn types() -> MutMap { SolvedType::Apply(Symbol::LIST_LIST, vec![attr_type(u, a)]), ], ), - SolvedType::Apply( - Symbol::ATTR_ATTR, - vec![ - shared(), - SolvedType::Func(vec![attr_type(u, a)], Box::new(flex(b))), - ], - ), + shared(SolvedType::Func(vec![attr_type(u, a)], Box::new(flex(b)))), ], list_type(star2, b), ) @@ -744,13 +743,10 @@ pub fn types() -> MutMap { SolvedType::Apply(Symbol::LIST_LIST, vec![attr_type(u, a)]), ], ), - SolvedType::Apply( - Symbol::ATTR_ATTR, - vec![ - shared(), - SolvedType::Func(vec![attr_type(u, a), flex(b)], Box::new(flex(b))), - ], - ), + shared(SolvedType::Func( + vec![attr_type(u, a), flex(b)], + Box::new(flex(b)), + )), flex(b), ], flex(b), @@ -939,13 +935,10 @@ pub fn types() -> MutMap { SolvedType::Apply(Symbol::SET_SET, vec![attr_type(u, a)]), ], ), - SolvedType::Apply( - Symbol::ATTR_ATTR, - vec![ - shared(), - SolvedType::Func(vec![attr_type(u, a), flex(b)], Box::new(flex(b))), - ], - ), + shared(SolvedType::Func( + vec![attr_type(u, a), flex(b)], + Box::new(flex(b)), + )), flex(b), ], flex(b), diff --git a/compiler/solve/tests/test_uniq_solve.rs b/compiler/solve/tests/test_uniq_solve.rs index 72d8f853f8..b1355a811f 100644 --- a/compiler/solve/tests/test_uniq_solve.rs +++ b/compiler/solve/tests/test_uniq_solve.rs @@ -2086,7 +2086,7 @@ mod test_uniq_solve { fn list_repeat() { infer_eq( indoc!("List.repeat"), - "Attr * (Attr * Int, a -> Attr * (List a))", + "Attr * (Attr * Int, Attr Shared a -> Attr * (List (Attr Shared a)))", ); }