typelevel / cats

Lightweight, modular, and extensible library for functional programming.
https://typelevel.org/cats/
Other
5.25k stars 1.21k forks source link

Consider making transformer types non-final #434

Open milessabin opened 9 years ago

milessabin commented 9 years ago

It's common to want simple names for transformer stacks, eg.,

type OptionalWork[T] = OptionT[Work, T]

Type aliases are somewhat second class in Scala however. In particular they don't have proper companion objects, and objects of the same name aren't searched for corresponding implicit definitions.

If transformers were non-final it would be possible to define a trait rather than a type alias,

trait OptionalWork[T] extends OptionT[Work, T]

In which case a useful companion object would be a possibility.

ceedubs commented 9 years ago

@milessabin is it important that they would be a trait? I haven't found myself wanting this functionality, but if we were to make this change I was wondering if an abstract class would suffice, as it would allow methods to be added to the transformer without breaking binary compatibility.

ceedubs commented 9 years ago

Hmm actually these would be non-final, but they wouldn't be abstract at all, would they? Would it just be a class?

milessabin commented 9 years ago

A class is just fine.

dwijnand commented 9 years ago

Isn't it possible to define a value alias for the companion object?

milessabin commented 9 years ago

It is, but it wouldn't be considered as part of the implicit scope.

kubukoz commented 6 years ago

What's the status on this? Are there any reasons not to make transformers non-final?

cc @kailuowang @LukaJCB

kailuowang commented 6 years ago

The implicit search scope includes the object where the alias is defined. So there is less need for an official companion object. That is you can define instances in the same object where alias is defined.