Deriving Scalaz

6,244 views

Published on

Talk given to the Melbourne Scala User Group, walking through why (and how) Scalaz came about.

Published in: Technology
0 Comments
12 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,244
On SlideShare
0
From Embeds
0
Number of Embeds
82
Actions
Shares
0
Downloads
119
Comments
0
Likes
12
Embeds 0
No embeds

No notes for slide



















  • Deriving Scalaz

    1. 1. Nick Partridge @nkpart Scalaz (scahla-zed)
    2. 2. Scalaz New datatypes: • Validation • NonEmptyList • Dlist • More
    3. 3. Scalaz Extensions to standard classes • OptionW • ListW • etc.
    4. 4. Scalaz Implementation of every single general function you need. • Ad-hoc Polymorphism • Traits + Implicit Parameters + Implicit Conversions.
    5. 5. Ad-hoc Polymorphism • What is polymorphism? def head[T](xs: List[T]): T = ... Any T will be fine.
    6. 6. Ad-hoc Polymorphism • What makes it ad-hoc? Restrictions. def show[T](t: T): String =... Not all T’s can be Strings.
    7. 7. Ad-hoc Polymorphism • Typically achieved through interitance. def show[T <: Show[T]](t: T) = ...
    8. 8. Ad-hoc Polymorphism • In scalaz, we use Traits • But no Inheritance. • Make it nice: • Implicit parameters and implicit conversions.
    9. 9. Live Demo def sum(xs: List[Int]) : Int to def sum[M[_], A](xs: M[A])(...): A
    10. 10. Typeclasses in Scalaz • Monoid - append, zero • FoldLeft • Functor - map • Monad - bind, return • Many more...
    11. 11. Making it Nice Questions? Live code. Pimping time.
    12. 12. Making it Nice The Pimps of Scalaz • Identity -> A • MA -> M[A] • MAB -> M[A, B] • More as necessary -> One per ‘kind’
    13. 13. Making it Nice object Scalaz extends ... { ... } • Includes all Implicit conversions • Pimps and Extensions • General constructors: • some(x), none
    14. 14. Making it Nice Usage: import scalaz._ import Scalaz._ ... List(1,2) |+| List(3,4)
    15. 15. New Datatypes • NonEmptyList • Validation
    16. 16. NonEmptyList • Guaranteed Not Empty. • Construct via Identity: • value.wrapNel • General constructors: • nel(head, tail) • nel1(head, tail...) <- varargs
    17. 17. Validation • Disjunction • Right-biased Either • Failures on the left. • Constructors: • value.fail, value.success • success(value), failure(value)
    18. 18. Scalaz - Console Live demo • NonEmptyList • Validation • OptionW - ~
    19. 19. Learn More. • scalaz/examples • `Typeclassopedia` • Haskell (particularly the wiki) • #functionaljava • Mailing list: http://code.google.com/p/scalaz • Source: http://github.com/scalaz/scalaz

    ×