New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typeclasses in perspective #2

Open
dcastro opened this Issue Jun 17, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@dcastro
Copy link
Owner

dcastro commented Jun 17, 2018

Comments left here will be displayed on this blog post: https://diogocastro.com/blog/2018/06/17/typeclasses-in-perspective/

@aaronj1335

This comment has been minimized.

Copy link

aaronj1335 commented Oct 27, 2018

Thanks for the great write-up; I learned a lot! I'm still pretty new to static-typing, so I find stuff like this really helpful.

Is my understanding correct that the Java example in the "Conditional implementation" section:

class List<A> implements Encodable {
  public Json toJson() { ... }
}

While this isn't possible in Java, it's essentially what Kotlin extension functions allow? So that means that while Kotlin's type system solves the "Extensibility" shortcoming mentioned in this article, the other four still remain?

@lindig

This comment has been minimized.

Copy link

lindig commented Oct 27, 2018

Very clear presentation!

@dcastro

This comment has been minimized.

Copy link
Owner

dcastro commented Oct 27, 2018

@aaronj1335, @lindig: Thank you!

@aaronj1335: I'm not familiar with Kotlin, but from scanning that link, Kotlin's extension functions look a lot like C#'s extension methods, which are just syntactic sugar for static methods: x.f() gets compiled to f(x).

These would allow you to "add" a toJson method to lists, yes, but it wouldn't allow you to abstract over all "encodable things". E.g., you would still not be able to pass lists into def postAsJson[A <: Encodable](body: A): Future[HttpResponse].

Even though they are convenient, extension functions/methods are not a means of abstraction.

@aaronj1335

This comment has been minimized.

Copy link

aaronj1335 commented Oct 28, 2018

Ah, that makes sense — a toJson method on a type isn't as helpful if you need to write stuff that accepts that specific type in order to call it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment