Foundationপ্রথম নীতি থেকে
LEVEL 5 · Programming Languages

Parametric Polymorphism

প্যারামেট্রিক পলিমরফিজম

Type-parameterized code — একই function/data structure সব type-এ হুবহু এক behavior-এ কাজ করে (`id : ∀a. a → a`)।

Ad-hoc (overloading/typeclass — type অনুযায়ী ভিন্ন code) বনাম parametric (type অনুযায়ী একই code):

length :: [a] -> Int        -- element-কে ছুঁয়েও দেখে না
  • Parametricity theorem (“theorems for free”): type signature-ই behavior-কে অনেকটা constrain করে — [a] -> [a] -> [a]-এর বৈধ implementation খুবই সীমিত
  • Implementation দুই পথ: erasure (Haskell/Generic Java — runtime-এ type নেই) বনাম reification (C#/.NET generics — runtime-এ type আছে, per-type specialization)
  • Rust monomorphization = compile-time copy per type — erasure-র উল্টো দিক, zero-cost