ncbag
Re:Approximating sum types in Python with Pydantic
on Thursday August 15, 2024 @06:12AM (#41254479)
Yes, the following is so easy in OCaml, it would be a major undertaking in Python:
type committer =
InnerCircle of string
| NPC of string
| Dissenter of string
;;
type coc_reaction =
DoNothing
| ThreeMonthsWithoutHumiliation
| PublicDefamation
;;
let adjudicate = function
InnerCircle _ -> DoNothing
| NPC _ -> ThreeMonthsWithoutHumiliation
| Dissenter _ -> PublicDefamation
;;
# adjudicate (InnerCircle "Wouters");;
- : coc_reaction = DoNothing
# adjudicate (Dissenter "Peters");;
- : coc_reaction = PublicDefamation
Just use another language, also for social and professional reasons.