2
วิธีลดการทำสำเนารหัสเมื่อจัดการกับประเภทผลรวมซ้ำ
ฉันกำลังทำงานกับล่ามง่าย ๆ สำหรับภาษาการเขียนโปรแกรมและฉันมีชนิดข้อมูลเช่นนี้: data Expr = Variable String | Number Int | Add [Expr] | Sub Expr Expr และฉันมีฟังก์ชั่นมากมายที่ทำสิ่งที่ง่ายเช่น: -- Substitute a value for a variable substituteName :: String -> Int -> Expr -> Expr substituteName name newValue = go where go (Variable x) | x == name = Number …