Hacker News new | ask | show | jobs
by roberthensing 3618 days ago
Type class instance parameters must be explicit in Scala, whereas Haskell can usually infer them. That might make a free monad approach more interesting in Scala.

However, if you really want to introduce this complexity in Scala, you will probably first write some nice high-level code, then discover that it causes a stack overflow, then have to learn about the TailRec monad, figure out how to stack your (free-like) monad on top of it, therefore learn monad transformers, which you probably wanted to avoid by using a free-like monad. A library may solve part of the problem for you, but you will have to be aware of your own stack usage all the time. And when it works you should tune your JVM garbage collector for many (many) short-lived objects.

I would either keep it simple in Scala or choose a language that supports this kind of abstraction in a less painful way.

1 comments

> Type class instance parameters must be explicit in Scala

In Scala, wouldn't this be solved with implicits? i.e. implicit 'instances' are in Singleton Objects that one simply brings into scope with an import.

In Scala, the implicit arguments are implicit, yes, but the parameter is not. You will have to declare the implicit parameter, even if you omit a type signature.

I think I forgot to mention the lack of type class coherence. That's also something you should be aware of when you start using type classes.