9148c358d0
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를 Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류. - 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로 자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거, 동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거. - 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming, Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business, Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로, 나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는 title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백). 원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지. - 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서. - 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는 지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지. - Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경. - 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
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 종류 정리 |