Introduction and hlists part 1 23 noviembre, 2015 23 noviembre, 2015 javifdev english generic, heterogeneous, hlist, list, miles, sabin, shapeless, syntax, type my good friends from scalera asked me if i would want to write a post for them, and they made me an offer i couldnt refuse, well get you a beer they. You can play with it by typing oneline expressions and observing the results. The illustrations are brought to life through colorful. Doing things at compiletime that would more commonly be done at runtime, keeping precise track of the type of each element in a list, being able to translate from tuples to hlists to case classes, creating polymorphic functions as opposed to methods. It provides purely functional data structures to complement those from the scala standard library. The line chart is based on worldwide web search for the past 12 months. There are a few interactive resources for trying out scala, to get a look and feel of the language. Please submit by clicking on the suggest link at the bottom of each page. Shapeless is an exploration of this space in scala, and this presentation shows some of its capabilities and applications and also explains some. First class lazy values tie implicit recursive knots traversals and transformations of recursive types eg. How many programming languages have been called lisp in sheeps clothing.
Of course, the working language has in each case been changed from scheme to scala. Thats not a secret and ill be forever grateful to their authors. Scalaz stream is a relatively new concurrency and dataflow library for scala. Ive ran a benchmark and im glad to report that the monix task beats in performance both such results are actually unexpected, because the monix task has to do tricks in order to be cancelable, a. Scala exercises is a series of lessons and exercises created by 47 degrees. Either which is rightbiased, works great in for comprehensions and comes with some additional utilities. Book an online course for your team, taught via live video conferencing. Otherwise, you might as well go with cats my own preference. When we started writing advanced scala we thought it was a book about how to use scalaz. Underscores scala books are now open source hacker news. Shapeless is a library provided by scala that can be used with a build tool like sbt.
It introduces generic encodings of product and coproduct types case classes and sealed traits, and shows how to implement type classes by solving problems at. Scalaz is a library for doing pure functional programming in scala programming language. For the second article of the scalaz features for everyday usage well look at the subject of monad transformers and the reader monad. The answers are usually varied, some people suggest starting with runars book, others with the coursera course. Since then it has evolved from being a resolutely experimental. The goal of this blog post series is to introduce various components of scalaz, and hopefully through this allow folks to gain an understanding towards the power of scalaz. Getting started with shapeless by julien tournay heterogenous lists, polymorphic function values, generic, tuples, lenses. For the most part, though, the book concentrates on exploring popular libraries such as scalaz, cats, monocle, circe, monix, shapeless, doobie, 4s, finch etc and discussing on a more basic level than the red book the principles they are written on.
This book justifies every concept with practical examples, including writing a web application. Strictly speaking, all three libraries have quite different goals and applications. Ive got the shapeless book and found it really good. Scala how to call a function in another file in scala. Once you are familiar with the basics of scala you will appreciate having this source of invaluable examples and precise explanations of scala on hand. It explores techniques that are usually considered nontrivial and shows their use in real projects. If you already know scala but want to go deeper, this is the book for you.
Shapeless requires more implicits, and more type classes. The shapelesscontrib project also contains automatically derived type class instances for scalaz, spire and scalacheck. Functional programming in scala is a very interesting, but extremely challenging book. Interaction between shapeless fieldtype, and scalaz tagged.
Monad transformers come in handy when you have to deal with nested monads, which happens suprisingly often. Basically they are a smooth introduction to shapeless, something to warm up. The book walks you through one of the main use cases for shapeless automatic, boilerplatefree derivation of type class instances. Algebra started as a unification of spire and algebird and now covers the core subset of category theory abstractions. Scalaz is a scala library for functional programming. This library and its community is one among the reasons that keep scala attractive to me. In my experience, most newbies eventually succeed in grasping the language, but it doesnt mean they learn a new skill set in the most efficient way possible.
Furthermore, the examples make use of scalas objectoriented constructs where appropriate. Polymorphic function values heterogenous lists tuples arity hmap singletons literals coproducts generic lenses auto typeclass derivation lazy type safe cast type checking lenses. One thing it is not is a scala book, despite that the name may make you think. It is possible that some search terms could be used in multiple areas and that could skew some graphs. It supports natural transformations, which are familiar from libraries like scalaz. What i liked about this book is that the explanations of most of the recipes are simple and clear, on the other hand, being scala mainly a functional programming language, there are just few recipes that approach a solution in a. As for the cats vs scalaz debate, in a book im currently working on i decided to treat scalaz as an extension to the standard library and cats as a category theory library. Its a great way to get a brief introduction to scala while testing your knowledge along the way. Functional programming for by sam halliday pdfipadkindle. The usual way to start working with scalaz is to import all its definitions with the following. This is a book that is full of simple examples that could give you a kick start in the scala world, specially if you are coming from java. Miles sabin explains dependent typing in scala, the shapeless project that demonstrates these concepts, static typing improvements in scala and scala macros.
Our projects cover a wide range of domains, from general functional programming to tooling. It is true that scalaz also provides category theory stuff, but this separation of concerns greatly simplifies things. Scalaz vs algebra vs cats which one should i learnuse. Download it once and read it on your kindle device, pc, phones or tablets. No hard copies yet for the cats book it isnt quite finished. But you can also rely on it for large mission critical systems, as many companies, including twitter, linkedin, or intel do. Coproduct in shapeless, scalaz, or cats is exactly what you want. Cats and scalaz are very similar and many concepts translate directly. Many of their examples and exercises are also present here.
The course works through several in depth examples of type class derivation designed to cover the main. Scalaz does provide a zip tag for stream and the appropriate zippy applicative instance, but as far as i know its still pretty broken. The type astronauts guide is aimed at experienced scala hitch hikers with an interest in generic programming and boilerplate elimination. This book goes beyond simple scala usage and covers some advanced topics. Im not a super expert of scala compilation but the price you pay with shapeless is that the compiler will have harder times with shapeless around at least is my experience and will slow down. If you sign up with a real email address youll get updates. Essential shapeless is a course aimed at experienced scala developers wanting to eliminate boilerplate from their codebases. Shapes are everywhere, from buildings and machines, to nature and people. This is a book about functional programming itself, and the language it uses for examples simply happens to be scala.
Cats interoperates with algebra via the catskernel module and provides some additional things related to categories on top of that. The type astronauts guide to shapeless book underscore. Shapeless is a type class and dependent type based generic programming library for scala. This book is for the typical scala developer, probably with a java background. We provide type classes, instances, conversions, testing, supplements to the standard library, and much more. But what happens when a shape appears that doesnt look like any shape at all. Miles sabin on dependent types with scala, shapeless. Ive been struggling to learn the library, and figured id write down my thoughts in the hopes of making other peoples learning experience easier.
We cover type classes, iteratees, category theory and look at some purely functional libraries. The shapeless shape is a simple, delightful story about a unique character who takes an unexpected path to find a place in a world of shapes. About once a week, someone on the scala subreddit asks for advice on how to learn scala. First read programming in scala or essential scala. Scrap your boilerplate and derive type classes with shapeless. Part i introduces the general mechanisms for type class derivation in shapeless. For instance when you have to work with nested futureoption or. Broadly speaking, shapeless is about programming with types. Useful methods using the pimp my library approach, many types have extra methods available. Youll have access to the book s content prior to its print publication, and can participate in its creation by submitting feedback. Near as i can tell, its singlebox use cases are the same as akkas, provided you dont plan to build a distributed system.
Whichever one you pick, imo hands down the best resource for learning them is the book. Cats vs scalaz for functional programming in scala. Suffers from massive migraines and bad sleep quality. Getting started with shapeless ive been playing with scala for 7 years and with shapeless for a couple of years now. My ebook about advanced scala topics and libraries.
Interestingly, scalaz offers an alternative to scala. Towards scalaz part 1 a lot of people see scalaz as a hard fringe, ivory tower, not suited for realworld applications library, which is unfortunate. The book provides both an authoritative reference for scala and a systematic tutorial covering all the features in the language. The following blog posts are introductory to shapeless. Advanced scala with cats advancedscala but be warned, the. This book is for the typical scala developer, probably with a java background, who is both sceptical and curious about the functional programming fp paradigm.
1444 1020 1608 216 155 265 1517 1082 278 1230 794 662 1217 1006 890 668 1118 839 354 724 906 7 1543 578 812 1650 1549 691 892 1237 192 1407 573 849 1424 491 1211 760 244 1146 968 1487 625 747