คำถามติดแท็ก recursive-type

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 …
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.