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

Cool to see a post about this sort of thing! I came up with a similar pattern a while ago (using Flow instead of TypeScript) for a lambda calculus evaluator. I ended up using a code generation approach so I define my datatypes in one file and the `match` method and `Matcher` interface are generated for me.

Here's where I define the five cases for a lambda calculus expression undergoing evaluation:

https://github.com/alangpierce/LambdaCalculusPlayground/blob...

Here are the autogenerated types for those cases (there's other code to make it work at runtime):

https://github.com/alangpierce/LambdaCalculusPlayground/blob...

And here's a simple example of using it:

https://github.com/alangpierce/LambdaCalculusPlayground/blob...




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

Search: