Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Typelevel's path to Scala 3

Lars Hupel
February 13, 2021

Typelevel's path to Scala 3

Scala 3 is just around the corner. Both EPFL and the broader community have put a lot of work into making this Scala release a success. In this talk, I will outline some of the history behind Scala 3 and what steps we took in the Typelevel ecosystem to get ready for Scala 3, and keep up with its development.

Lars Hupel

February 13, 2021
Tweet

More Decks by Lars Hupel

Other Decks in Programming

Transcript

  1. T y p e l e v e l ’s

    p a t h t o S c a l a 3 L a r s H u p e l S c a l a L o v e i n t h e C i t y 2 0 2 1 - 0 2 - 1 3
  2. T y p e l e v e l F

    o u n d e d i n 2 0 1 3 a t N o r t h e a s t S c a l a S y m p o s i u m
  3. T y p e l e v e l F

    o u n d e d i n 2 0 1 3 a t N o r t h e a s t S c a l a S y m p o s i u m T o d a y : 7 0 + p r o j e c t s , v i b r a n t e c o s y s t e m
  4. T y p e l e v e l p

    r o j e c t s C e n t r a l t h e m e : S c a l a - i d i o m a t i c F u n c t i o n a l P r o g r a m m i n g
  5. T y p e l e v e l p

    r o j e c t s C e n t r a l t h e m e : S c a l a - i d i o m a t i c F u n c t i o n a l P r o g r a m m i n g • . . . w i t h a s l i t t l e h a s s l e a s p o s s i b l e
  6. T y p e l e v e l p

    r o j e c t s C e n t r a l t h e m e : S c a l a - i d i o m a t i c F u n c t i o n a l P r o g r a m m i n g • . . . w i t h a s l i t t l e h a s s l e a s p o s s i b l e • . . . w i t h a s l i t t l e r u n t i m e o v e r h e a d a s p o s s i b l e
  7. T y p e l e v e l p

    r o j e c t s C e n t r a l t h e m e : S c a l a - i d i o m a t i c F u n c t i o n a l P r o g r a m m i n g • . . . w i t h a s l i t t l e h a s s l e a s p o s s i b l e • . . . w i t h a s l i t t l e r u n t i m e o v e r h e a d a s p o s s i b l e • . . . a s s a f e a s p o s s i b l e
  8. T y p e c l a s s e

    s S u p r e m e l y u s e f u l t o o l , p i o n e e r e d i n H a s k e l l
  9. T y p e c l a s s e

    s S u p r e m e l y u s e f u l t o o l , p i o n e e r e d i n H a s k e l l class Semigroup a => Monoid a where mempty :: a mconcat :: [a] -> a mconcat = foldr mappend mempty
  10. T y p e c l a s s e

    s S u p r e m e l y u s e f u l t o o l , p i o n e e r e d i n H a s k e l l class Semigroup a => Monoid a where mempty :: a mconcat :: [a] -> a mconcat = foldr mappend mempty I t J u s t W o r k s ™ !
  11. T y p e c l a s s e

    s i n S c a l a . . . n o w w e j u s t n e e d t o e n c o d e t h e m i n S c a l a
  12. T y p e c l a s s e

    s i n S c a l a . . . n o w w e j u s t n e e d t o e n c o d e t h e m i n S c a l a • m u l t i p l e i n h e r i t a n c e ?
  13. T y p e c l a s s e

    s i n S c a l a . . . n o w w e j u s t n e e d t o e n c o d e t h e m i n S c a l a • m u l t i p l e i n h e r i t a n c e ? • s y n t a x ? ?
  14. T y p e c l a s s e

    s i n S c a l a . . . n o w w e j u s t n e e d t o e n c o d e t h e m i n S c a l a • m u l t i p l e i n h e r i t a n c e ? • s y n t a x ? ? • g l o b a l c o n f l u e n c e ? ? ?
  15. T y p e c l a s s e

    s i n S c a l a . . . n o w w e j u s t n e e d t o e n c o d e t h e m i n S c a l a • m u l t i p l e i n h e r i t a n c e ? • s y n t a x ? ? • g l o b a l c o n f l u e n c e ? ? ?
  16. T h e r i s e o f t

    h e m a c r o s
  17. T y p e c l a s s e

    s , e n c o d e d I n 2 0 1 5 , M i c h a e l P i l q u i s t s t a r t e d s i m u l a c r u m . G o a l : c o n s i s t e n t e n c o d i n g a c r o s s d i f f e r e n t p r o j e c t s , 0 b o i l e r p l a t e
  18. S i m u l a c r u m

    I n p u t import simulacrum._ @typeclass trait Semigroup[A] { @op("|+|") def append(x: A, y: A): A }
  19. S i m u l a c r u m

    O u t p u t object Semigroup { def apply[A](implicit instance: Semigroup[A]): Semigroup[A] = instance // ... }
  20. S i m u l a c r u m

    M o r e o u t p u t object Semigroup { trait Ops[A] { def typeClassInstance: Semigroup[A] def self: A def |+|(y: A): A = typeClassInstance.append(self, y) } }
  21. S i m u l a c r u m

    E v e n m o r e o u t p u t object Semigroup { trait ToSemigroupOps { implicit def toSemigroupOps[A](target: A)(implicit tc: Semigroup[A]): Ops[A] val self = target val typeClassInstance = tc } } object nonInheritedOps extends ToSemigroupOps }
  22. S i m u l a c r u m

    Y e t m o r e o u t p u t object Semigroup { trait AllOps[A] extends Ops[A] { def typeClassInstance: Semigroup[A] } object ops { implicit def toAllSemigroupOps[A](target: A)(implicit tc: Semigroup[A]): AllO val self = target val typeClassInstance = tc } } }
  23. B u t i t w o r k s

    ! S i m u l a c r u m s o l v e d a t o n o f i s s u e s W e c a n w r i t e x |+| y!
  24. B u t i t w o r k s

    ! S i m u l a c r u m s o l v e d a t o n o f i s s u e s W e c a n w r i t e x |+| y! U s e d b y C a t s a n d t o n s o f t h i r d - p a r t y l i b r a r i e s
  25. W e ’ r e n o t d o

    n e y e t S i m u l a c r u m d i d n ’ t s o l v e t h e p e r f o r m a n c e i s s u e .
  26. W e ’ r e n o t d o

    n e y e t S i m u l a c r u m d i d n ’ t s o l v e t h e p e r f o r m a n c e i s s u e . I n p u t x |+| y
  27. W e ’ r e n o t d o

    n e y e t S i m u l a c r u m d i d n ’ t s o l v e t h e p e r f o r m a n c e i s s u e . O u t p u t Semigroup.ops.toAllSemigroupOps(x).|+|(y)
  28. E n t e r M a c h i

    n i s t S p l i t o u t o f S p i r e b y E r i k O s h e i m i n 2 0 1 4
  29. E n t e r M a c h i

    n i s t S p l i t o u t o f S p i r e b y E r i k O s h e i m i n 2 0 1 4 N o w ( 2 0 2 0 ) a r c h i v e d a n d r e - i n c o r p o r a t e d i n t o S p i r e
  30. T y p e c o n s t r

    u c t o r s
  31. T y p e c o n s t r

    u c t o r p o l y m o r p h i s m case class EitherT[F[_], A, B](value: F[Either[A, B]]) { // ... }
  32. T y p e c o n s t r

    u c t o r p o l y m o r p h i s m case class EitherT[F[_], A, B](value: F[Either[A, B]]) { // ... } S c a l a i s t h e o n l y l a n g u a g e t h a t c a n d o t h a t ! *
  33. T y p e c o n s t r

    u c t o r p o l y m o r p h i s m L a n d e d i n S c a l a 2 . 5 b y A d r i a a n M o o r s ( 2 0 0 7 )
  34. T y p e c o n s t r

    u c t o r p o l y m o r p h i s m L a n d e d i n S c a l a 2 . 5 b y A d r i a a n M o o r s ( 2 0 0 7 ) C o m p l e t e g a m e - c h a n g e r
  35. “ A s s o o n a s y

    o u g i v e S c a l a p r o g r a m m e r s a n e w t o y , t h e y w i l l s t a r t a b u s i n g i t i n w a y s y o u c a n ’ t i m a g i n e . ” – a n c i e n t S c a l a p r o v e r b
  36. S c a l a i s n ’ t

    H a s k e l l H a s k e l l instance Monad (Either a) where {- ... -}
  37. S c a l a i s n ’ t

    H a s k e l l H a s k e l l instance Monad (Either a) where {- ... -} S c a l a implicit val eitherMonad[A]: Monad[({ type λ[β] = Either[A, β] })#λ] = // ...
  38. k i n d - p r o j e

    c t o r E v e n m a c r o s c a n ’ t f i x m i s s i n g s y n t a x . * W e n e e d a c o m p i l e r p l u g i n !
  39. k i n d - p r o j e

    c t o r E v e n m a c r o s c a n ’ t f i x m i s s i n g s y n t a x . * W e n e e d a c o m p i l e r p l u g i n ! implicit val eitherMonad[A]: Monad[Either[A, ?]] = // ...
  40. S I - 2 7 1 2 def foo[F[_], A](fa:

    F[A]) = // ... // doesn't compile! // Either[_, _] is not an F[_] foo(x: Either[String, Int])
  41. U n a p p l y D e p

    e n d e n t m e t h o d t y p e s + t o n s o f b o i l e r p l a t e = S I - 2 7 1 2 h a c k
  42. U n a p p l y trait Unapply[TC[_[_]], MA]

    { type M[_] type A def TC: TC[M] def subst: MA => M[A] } // okay ...
  43. U n a p p l y implicit def unapply3MTLeft[TC[_[_]],

    F[_[_],_,_], AA[_], B, C] (implicit tc: TC[F[AA,?,C]]): Aux3MTLeft[TC,F[AA, B, C], F, AA, B, C] = new Unapply[TC, F[AA,B,C]] { type M[X] = F[AA, X, C] type A = B def TC: TC[F[AA, ?, C]] = tc def subst: F[AA, B, C] => M[A] = identity } // the what now?!?!
  44. S e v e n y e a r s

    l a t e r . . . M i l e s f i x e s i t f o r S c a l a 2 .1 2 !
  45. S e v e n y e a r s

    l a t e r . . . M i l e s f i x e s i t f o r S c a l a 2 .1 2 ! ( . . . a n d f o r 2 .1 0 a n d 2 .1 1 w i t h a c o m p i l e r p l u g i n )
  46. S e v e n y e a r s

    l a t e r . . . M i l e s f i x e s i t f o r S c a l a 2 .1 2 ! ( . . . a n d f o r 2 .1 0 a n d 2 .1 1 w i t h a c o m p i l e r p l u g i n )
  47. T y p e c o n s t r

    u c t o r s i n D o t t y T h e D o t t y t e a m h a s t a k e n g r e a t c a r e t o c o n s o l i d a t e t h e c u r r e n t “ h a c k s ” T y p e l a m b d a s n o w b u i l t i n !
  48. S c a l a 2 m a c r

    o s L a n d e d i n S c a l a 2 .1 0 ( 2 0 1 2 ) E n a b l e d l o t s o f i n n o v a t i o n a c r o s s t h e b o a r d
  49. S c a l a 2 m a c r

    o s L a n d e d i n S c a l a 2 .1 0 ( 2 0 1 2 ) E n a b l e d l o t s o f i n n o v a t i o n a c r o s s t h e b o a r d S a d l y , n o t a v a i l a b l e a n y m o r e i n D o t t y
  50. M i g r a t i o n o

    f s c o d e c F i r s t s u p p o r t e d v e r s i o n : D o t t y 0 . 2 2 . 0 *
  51. M i g r a t i o n o

    f s c o d e c F i r s t s u p p o r t e d v e r s i o n : D o t t y 0 . 2 2 . 0 * R e q u i r e s c o m p l e t e r e i m p l e m e n t a t i o n b e t w e e n S c a l a 2 a n d D o t t y
  52. S c a l a 3 . 0 . 0

    i s n e a r ! l a n g u a g e f e a t u r e s s i m u l a c r u m m a n y m a j o r T y p e l e v e l p r o j e c t s r e l e a s e t r a i n
  53. S c a l a 3 . 0 . 0

    i s n e a r ! l a n g u a g e f e a t u r e s s i m u l a c r u m m a n y m a j o r T y p e l e v e l p r o j e c t s r e l e a s e t r a i n S t i l l l o t s t o d o ( M o n i x , h t t p 4 s , . . . )
  54. Q & A L a r s H u p

    e l � l a r s . h u p e l @ i n n o q . c o m � @ l a r s r _ h w w w . i n n o q . c o m
  55. L A R S H U P E L S

    e n i o r C o n s u l t a n t i n n o Q D e u t s c h l a n d G m b H L a r s i s k n o w n a s o n e o f t h e f o u n d e r s o f t h e T y p e - l e v e l i n i t i a t i v e w h i c h i s d e d i c a t e d t o p r o v i d i n g p r i n c i p l e d , t y p e - d r i v e n S c a l a l i b r a r i e s i n a f r i e n d l y , w e l c o m i n g e n v i r o n m e n t . A f r e q u e n t c o n f e r e n c e s p e a k e r , t h e y a r e a c t i v e i n t h e o p e n s o u r c e c o m - m u n i t y , p a r t i c u l a r l y i n S c a l a .
  56. S o u r c e s • https://twitter.com/ohbadiah/status/299937487713878016 •

    https://twitter.com/travisbrown/status/300015411125174273 • https://secure.trifork.com/dl/techmesh-london-2012/slides/JohnHughes_and_PhilipWadler_and_ SimonPeytonJones_KeynoteHaskellPracticalAsWellAsCool.pdf • https://www.reddit.com/r/shiba/comments/e6ec1e/angry_shiba/ • https://pixabay.com/vectors/people-jump-silhouette-group-male-4894818/