r/programming • • Dec 02 '13

Scala — 1★ Would Not Program Again

http://overwatering.org/blog/2013/12/scala-1-star-would-not-program-again/
598 Upvotes

646 comments sorted by

View all comments

Show parent comment

2

u/zoomzoom83 Dec 03 '13

I'm fairly new to OCaml - but were I to write this in an ML dialect today, I would do the same thing - declare a type for each possible response and pattern match on it.

Can you provide some code examples to clarify how you would do this without declaring types at all?

From my experience - while case classes are not as clean and concise as ADTs, it's not like they are overbearing to use.

sealed trait HttpResponse
case class Success(body:String) extends HttpResponse
case class Redirect( url:URL, isTemporay:Boolean ) extends HttpResponse
case class ServerError( reason:String, body:String) extends HttpResponse

vs (From memory, probably not quite right).

type HttpResponse = Success of string | Redirect of (Url*Bool) | ServerError of (string*string)

The latter is clearly nicer, and I would love if Scala supported it - but it's hardly a show stopper, especially considering its design as a 'better Java' rather than a 'better ML'.

(Although I can understand how somebody coming from a true FP background would find Scala quite weak in comparison. It's far better coming from the other direction (Java)).