As a user of F# I’ve been using lots of seq { } and async { } computation expressions, however I never really wrote my own. Lately I’ve be

Creating DSLs using F#’s Computation Expressions

submited by
Style Pass
2024-07-10 19:00:14

As a user of F# I’ve been using lots of seq { } and async { } computation expressions, however I never really wrote my own. Lately I’ve been getting more and more into making DSLs and I found CEs to be an absolutely god-send for this. They can make the code really succinct and can help you turn messy code into a neat list of instructions that is easy to follow.

So I thought that in this post we can make together a DSL that, inspired by DeckUI, will kick an Avalonia application which shows a presentation.

There’s already quite a few really nice examples of DSL that use CEs outside of the ones in the core library, the one that immediately comes to mind is FSHttp, which uses CEs to declare HTTP requests that are really easy to interpret:

Or projects like Validus that use the applicative nature of CEs to create powerful validations with a few single lines of code:

Leave a Comment