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

A History of Enterprise Monads

A History of Enterprise Monads

The early 2010’s were exciting times for Scala. The language & ecosystem started to professionalize, both from a technical (binary compatibility) and a community point of view (many conferences were started). Not too long after Lightbend – then Typesafe – was founded, I registered the typelevel.org domain on a whim and put together a rudimentary website advertising a few FP-minded Scala libraries. Fast forward to today: Typelevel is known for a wealth of functional libraries, beginner-friendly educational resources, a series of conferences and a distinct ecosystem – including a custom compiler – within the Scala community. In this talk, I’d like to examine what got us there and into the mainstream.

A1216674d5c9747bcdcc716872439137?s=128

Lars Hupel

May 05, 2021
Tweet

Transcript

  1. A H i s t o r y o f

    E n t e r p r i s e M o n a d s L a r s H u p e l Y O W ! L a m b d a J a m 2 0 2 1 - 0 5 - 0 5
  2. None
  3. None
  4. H u m b l e b e g i

    n n i n g s 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
  5. H u m b l e b e g i

    n n i n g s 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
  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
  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
  8. 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
  9. 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
  10. None
  11. C a t s

  12. 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
  13. 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
  14. 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 ™ !
  15. None
  16. None
  17. 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
  18. 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 ?
  19. 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 ? ?
  20. 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 ? ? ?
  21. 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 ? ? ?
  22. None
  23. 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
  24. 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 }
  25. 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 // ... }
  26. 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) } }
  27. 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 }
  28. 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 } } }
  29. None
  30. 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!
  31. 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
  32. S p i r e

  33. N u m e r i c s f o

    r S c a l a • s t a r t e d o u t a s a S I P i n 2 0 1 1 ( ! ) • e v o l v e d i n t o a d e d i c a t e d l i b r a r y • “ w h a t i f f u n c t i o n a l b u t a l s o f a s t ”
  34. W h a t a b o u t p

    e r f o r m a n c e ? 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 f t y p e c l a s s e s .
  35. W h a t a b o u t p

    e r f o r m a n c e ? 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 f t y p e c l a s s e s . I n p u t x |+| y
  36. W h a t a b o u t p

    e r f o r m a n c e ? 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 f t y p e c l a s s e s . O u t p u t Semigroup.ops.toAllSemigroupOps(x).|+|(y)
  37. 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
  38. 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
  39. S h a p e l e s s

  40. • s t a r t e d o u

    t a s a s e r i e s o f t a l k s i n 2 0 1 1 ( ! ) • s c r a t c h e d a n i t c h : h o w t o a b s t r a c t o v e r d a t a ? • p i o n e e r e d “ t y p e c l a s s d e r i v a t i o n ” • m a n y c o n c e p t s i n c o r p o r a t e d i n t o S c a l a 3
  41. T y p e C l a s s D

    e r i v a t i o n P r o b l e m : Y o u w a n t t o s e r i a l i z e a b u n c h o f c a s e c l a s s e s t o J S O N . S o l u t i o n : B o i l e r p l a t e ?
  42. T y p e C l a s s D

    e r i v a t i o n P r o b l e m : Y o u w a n t t o c o m p a r e a b u n c h o f c a s e c l a s s e s . S o l u t i o n : B o i l e r p l a t e . . . a g a i n ? !
  43. case class Account(owner: Person, balance: Int) case class Person(name: String,

    address: Address) case class Address(lines: List[String], country: Country) case class Country(code: String)
  44. type Account = Person :: Int :: HNil type Person

    = String :: Address :: HNil type Address = List[String] :: Country :: HNil type Country = String :: HNil
  45. I n A c t i o n

  46. C a t s E f f e c t

  47. • f u l l h i s t o

    r y a l m o s t i m p o s s i b l e t o t r a c e • d r a w s f r o m m u l t i t u d e o f i n f l u e n c e s • s u p p o r t s t h e r i s e o f a s y n c h r o n o u s s o f t w a r e c o n s t r u c t i o n
  48. None
  49. F u t u r e

  50. None
  51. s e r i o u s l y t

    h e a n s w e r i s a l m o s t a l w a y s . t r a v e r s e S o a r e w e n o t f l a t m a p p i n g t h a t s h i t a n y m o r e ? t r a v e r s e i s f l a t m a p p i n g t h a t s h i t o n o u r b e h a l f
  52. 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
  53. 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 .
  54. S o u r c e s • https://pixabay.com/photos/people-business-meeting-1979261/ •

    https://unsplash.com/photos/FaNUdWGJqBg • https://twitter.com/bodil/status/1383908807588204552/photo/1 • https://twitter.com/milessabin/status/1364523756601937921 • https://www.manning.com/books/functional-programming-in-scala • https://impurepics.com/posts/2021-03-31-cats-effect-3.html • https://twitter.com/tpolecat/status/721019769869045760