Leveraging the type system to avoid mistakes
If you like this, you&#x27;re probably also going to like Haskell&#x2F;OCaml&#x2F;Ada&#x2F;F#&#x2F;Coq (ML family of languages?):<p>I&#x27;ll leave links for Haskell since the only one of those I&#x27;ve tried and liked personally:<p><a href="https:&#x2F;&#x2F;www.haskell.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.haskell.org&#x2F;</a><p><a href="http:&#x2F;&#x2F;learnyouahaskell.com&#x2F;" rel="nofollow">http:&#x2F;&#x2F;learnyouahaskell.com&#x2F;</a><p>IMO Haskell is the type system you wanted Java to have, with even more strictness. While it&#x27;s possible to write unsafe haskell, just about everything you will read, and the language itself encourages you to push as many worries as you can to be solved by the type system.<p>If that doesn&#x27;t get you excited, there&#x27;s actually a saying that is mostly true in my experience writing Haskell -- &quot;If it compiles, it works&quot;(tm).<p>Also Haskell on the JVM if you want to dip your toes in:<p>- <a href="https:&#x2F;&#x2F;eta-lang.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;eta-lang.org&#x2F;</a><p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;Frege&#x2F;frege" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Frege&#x2F;frege</a><p>[EDIT] - If you try to learn haskell you&#x27;ll inevitably run into the M word which rhymes with Gonad. The best guide I&#x27;ve ever read is @ <a href="http:&#x2F;&#x2F;adit.io&#x2F;posts&#x2F;2013-04-17-functors,_applicatives,_and_monads_in_pictures.html" rel="nofollow">http:&#x2F;&#x2F;adit.io&#x2F;posts&#x2F;2013-04-17-functors,_applicatives,_and_...</a><p>BTW, be ye warned: when you start understanding&#x2F;getting cozy with the concepts introduced by Haskell you&#x27;ll wish they were everywhere, and they&#x27;re not. Languages without proper union types will look dumb to you, easy function composition&#x2F;points free style will be a daily desire, and monadic composition of a bunch of functions will be frustratingly absent&#x2F;ugly in other languages, not doing errors-as-values will look ironically error-prone.<p>[EDIT 2] - More relevant to the actual post, how you would do this in Haskell is using the `type` keyword (type aliasing, e.g. `type Email = String`) or the `newtype` keyword, which creates a new type that is basically identical (what the article talks about). Here&#x27;s some discussion on newtype:<p>- <a href="http:&#x2F;&#x2F;degoes.net&#x2F;articles&#x2F;newtypes-suck" rel="nofollow">http:&#x2F;&#x2F;degoes.net&#x2F;articles&#x2F;newtypes-suck</a> (this article is good, it describes the premise, promise, shortcomings, and workarounds, forgive the clickbaity title)<p>- <a href="https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;haskell&#x2F;comments&#x2F;4jnwjg&#x2F;why_use_newtype&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;haskell&#x2F;comments&#x2F;4jnwjg&#x2F;why_use_new...</a>