c24165b8bc
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게 [공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류. 문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인). - Topic_Programming → Domain_Programming (내부 구조 보존) - Topic_Graphic → Domain_Design - Topic_Business → Domain_Product - Topic_General → Domain_General - _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning), Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing) - 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서) - 빈 폴더 정리 (memory/procedures) - 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
4.7 KiB
4.7 KiB
id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
| id | title | category | status | canonical_id | aliases | duplicate_of | source_trust_level | confidence_score | verification_status | tags | raw_sources | last_reinforced | github_commit | tech_stack | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| wiki-2026-0508-generics-and-polymorphism | Generics and Polymorphism | 10_Wiki/Topics | verified | self |
|
none | A | 0.9 | applied |
|
2026-05-10 | pending |
|
Generics and Polymorphism
매 한 줄
"매 한 번 작성, 매 여러 type 에 작동". 매 parametric polymorphism (generics) + ad-hoc polymorphism (overloading / traits) + subtype polymorphism (inheritance) 의 셋이 modern type system 의 backbone. 2026 시점 TS 5.x conditional types, Rust trait + GAT, Go 1.21+ generics 가 매 mainstream.
매 핵심
매 polymorphism 의 종류
- Parametric: type parameter
<T>— 매 List, Vec, []T. - Ad-hoc: overloading, type classes, traits, interfaces with default impl.
- Subtype: 매 Liskov — Cat extends Animal.
- Row / Structural: TS object shape, OCaml row polymorphism.
매 dispatch
- Static (monomorphization): Rust, C++ template — 매 compile-time 에 specialize → zero overhead.
- Dynamic (vtable): Java interface, Go interface, Rust dyn Trait — 매 runtime indirection.
매 응용
- Collection / container 의 reuse.
- Algorithm 의 generic write (sort, map).
- API design 의 type-safe abstraction.
- Dependency injection 의 decoupling.
💻 패턴
TypeScript — generic constraint
function pluck<T, K extends keyof T>(items: T[], key: K): T[K][] {
return items.map(i => i[key]);
}
const names = pluck([{ id: 1, name: "Ada" }], "name"); // string[]
TS — conditional + infer
type ReturnT<F> = F extends (...a: any[]) => infer R ? R : never;
type X = ReturnT<() => Promise<number>>; // Promise<number>
Rust — trait + generic
trait Summable: Copy + std::ops::Add<Output = Self> + Default {}
impl<T: Copy + std::ops::Add<Output = T> + Default> Summable for T {}
fn sum<T: Summable>(xs: &[T]) -> T {
xs.iter().copied().fold(T::default(), |a, b| a + b)
}
Rust — GAT (Generic Associated Type)
trait LendingIterator {
type Item<'a> where Self: 'a;
fn next<'a>(&'a mut self) -> Option<Self::Item<'a>>;
}
Rust — dyn vs impl Trait
fn make_static() -> impl Iterator<Item = i32> { (0..10).filter(|x| x % 2 == 0) } // monomorphized
fn make_dyn() -> Box<dyn Iterator<Item = i32>> { Box::new(0..10) } // vtable
Go — generics (1.21+)
type Number interface { ~int | ~int64 | ~float64 }
func Sum[T Number](xs []T) T {
var total T
for _, x := range xs { total += x }
return total
}
Java — bounded wildcard (PECS)
// Producer Extends, Consumer Super
static double sum(List<? extends Number> xs) {
double s = 0; for (Number n : xs) s += n.doubleValue(); return s;
}
static void fillWithOnes(List<? super Integer> xs) { xs.add(1); }
Haskell — type class (ad-hoc)
class Eq a where
(==) :: a -> a -> Bool
instance Eq Int where x == y = primEqInt x y
매 결정 기준
| 상황 | Approach |
|---|---|
| Container reuse | parametric <T> |
| Multiple impl 의 한 interface | trait / interface |
| Hot path, type set 작음 | monomorphization (Rust, C++ template) |
| Heterogeneous collection | dyn Trait / interface{} / Box |
| Known finite variants | sum type (enum / discriminated union) — 매 generic 보다 simple |
기본값: TS / Java 는 generics + interface, Rust 는 generic + trait (static dispatch).
🔗 Graph
- 부모: TypeScript 타입 시스템 (TypeScript Type System) · Polymorphism
- 변형: Subtype Polymorphism
- Adjacent: Variance · Sum Types
🤖 LLM 활용
언제: API surface design / type signature 의 reasoning / variance bug 진단. 언제 X: 매 simple concrete type 만 쓰는 곳에 generic 강제 — 매 over-abstraction.
❌ 안티패턴
- Generic for one caller: 매 YAGNI — 매 concrete 부터.
- Unbounded
<T>의 남용: 매 actually 필요한 constraint 누락. - Variance 무시 (Java):
List<Cat>을List<Animal>자리에 — covariance bug. - dyn Trait everywhere (Rust): 매 hot path 에서 vtable cost 누적.
- Type erasure 의 망각 (Java): runtime 에
T의 reflection 시도.
🧪 검증 / 중복
- Verified (Pierce TAPL 2002, Rust Reference, TS Handbook 5.x, Go spec 1.21).
- 신뢰도 A.
🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — TS/Rust/Go/Java generics + polymorphism 종류 정리 |