Hacker News new | past | comments | ask | show | jobs | submit login

> In the pseudo-Haskell version, we would need to modify all 6 evaluation functions just to handle the new Expression subtype.

That's not true. I think you may be misunderstanding open unions (or polymorphic variants) here. Tags are types in and of themselves. That's why these are all `type alias`es. You could decide to modify the type alias if you'd like, but you don't have to. You can add the additional tag just to the call site.




So how would a subtype of Addition look here? Who would tell stringEvaluator how to handle this SmallNumberAddition?


There wouldn't be a subtype of Addition because Haskell doesn't have a notion of subtyping in the same way C# does. It would depend on the particulars of what the difference between SmallNumberAddition and Addition look like (in particular which parts are kept with the same functionality and which are different). The answer could be either a simple function or a typeclass depending on that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: