Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's particularly powerful if you can great an algebra of your domain. You can define invariants which are then enforced by the type system.

I use this a lot when writing C# code and the whole experience is getting better with every new release. Microsoft keep adding awesome stuff like ADTs which make working with these types a dream.



Do you have any resources you can recommend which describe how to create an algebra of a domain?


I’d recommend Scott Wlaschin’s excellent book “Domain Modelling made Functional”. The examples are in F# but the concepts apply much more broadly.



Thanks a lot for that video. Watched the whole thing on the spot. He is actually quite a good presenter and really gets the points across.


Came here to post this. I second this book heartily. If you design your types to be DD with raw, valid, invalid data then by the time you actually get to the database or API, you are sure that your code has passed through however many compile-time enforced validity checks (if you use F# or similar static strong type PL) before it got to this point.

That way, you don't need nearly as much defensive coding re: null checks etc. because the data has gone from 'some client typed some value in an input box, hope its valid' to 'this is an Address line that has been confirmed to be valid structure to pass to downstream systems'.

Pit of success is so much better than peak of success, and much easier to get in a static typed functional language vs. an OO language in my experience.


+1 for that book. It totally changed how I thought about types and their role in programming.


Agreed. This is a great book. It's changed the way I use statically-typed functional languages.

This article is very much in the same vein.


The best thing is that he writes F# in a way that is perfectly understandable by the domain experts so he can use the code as the ubiquitous language. In this way an intermediate representation to communicate with the users is not needed and there is nothing that needs to be kept in sync with the code.


Thanks!




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

Search: