shapeless is a type class and dependent type based generic programming library for Scala. It had its origins in several talks by Miles Sabin (@milessabin), given over the course of 2011, on implementing scrap your boilerplate and higher rank polymorphism in Scala. Since then it has evolved from being a resolutely experimental project into library which, while still testing the limits of what's possible in Scala, is being used widely in production systems wherever there are arities to be abstracted over and boilerplate to be scrapped.
A feature overview of shapeless-2.0.0 can be found here. If you are upgrading from shapeless-1.2.4 you will find the release notes and migration guide useful.
shapeless is part of the typelevel family of projects along with Scalaz and Spire. It is an Open Source project under the Apache License v2, hosted on github. Binary artefacts are published to the Sonatype OSS Repository Hosting service and synced to Maven Central.
There is a mailing list for discussion around generic programming in Scala in general and shapeless in particular. You will also find many of the main shapeless contributors on IRC in the #shapeless channel on freenode. Questions about shapeless are often asked and answered under the shapeless tag on StackOverflow. Some articles on the implementation techniques can be found on Miles's blog, and Olivera, Moors and Odersky, Type Classes as Object and Implicits is useful background material.
Support for Scala 2.9.x is still available via the shapeless-1.2.4 release (feature overview here). It isn't straightforward to bring the latest shapeless features to Scala versions which don't support implicit macros, and this release should be treated as a stopgap until you are able to move your project to Scala 2.11. It might, however, be feasible to backport some of the updates via a compiler plugin for Scala 2.9.x, and anyone interested in contributing or sponsoring such work should get in touch.
The shapeless project supports the Typelevel code of conduct and wants all of its channels (mailing list, IRC, github, etc.) to be welcoming environments for everyone.
Whilst shapeless is a somewhat "advanced" Scala library, it is a lot more approachable than many people think. Contributors are usually available to field questions, give advice and discuss ideas on #shapeless and the mailing list, and for people wanting to take their first steps at contributing we have a selection of open issues flagged up as being good candidates to take on. No contribution is too small, and guidance is always available.
Binary release artefacts are published to the Sonatype OSS Repository Hosting service and synced to Maven Central. Snapshots of the master and scala-2.10.x branches are built using Travis CI and automatically published to the Sonatype OSS Snapshot repository. To include the Sonatype repositories in your SBT build you should add,
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
)
Please be aware that SBT 0.13.6 has an issue related to its new name hashing feature which when compiling with shapeless might cause SBT to loop indefinitely consuming all heap. Workarounds are to move to an earlier (0.13.5) or later (0.13.7) SBT version or disable name hashing by adding,
incOptions := incOptions.value.withNameHashing(false)
to your settings.
Builds are available for Scala 2.11.0 and later and for Scala 2.10.4.
// For Scala 2.11.4
scalaVersion := "2.11.4"
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.0.0"
)
For Scala 2.10.x you must specify a Scala version of at least 2.10.2, and add either cross CrossVersion.full
or
provide an explicit Scala version suffix to your shapeless dependency,
// For Scala 2.10.x >= 2.10.2
scalaVersion := "2.10.4"
libraryDependencies ++= Seq(
"com.chuusai" % "shapeless_2.10.4" % "2.0.0"
// "com.chuusai" % "shapeless" % "2.0.0" cross CrossVersion.full // Alternatively ...
)
Note that Scala 2.10.x releases are compatible with each other starting from 2.10.2, so a mismatch in minor versions above would be fine.
Builds are available for Scala 2.11.0 and later and for Scala 2.10.4. The main line of development for shapeless 2.1.0 will be Scala 2.11.4 with Scala 2.10.x supported via the macro paradise compiler plugin.
scalaVersion := "2.11.4"
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.1.0-SNAPSHOT" changing()
)
Note that for Scala 2.10.4 you must provide an explicit Scala version suffix to your shapeless dependency,
scalaVersion := "2.10.4"
libraryDependencies ++= Seq(
"com.chuusai" % "shapeless_2.10.4" % "2.1.0-SNAPSHOT" changing()
)
Builds are available for Scala 2.9, 2.10 and 2.11. If you are working with Scala 2.10.2 or later you should use shapeless-2.0.0 instead.
If your project is built with Scala 2.9.3 or earlier, then you will need to specify the -Ydependent-method-types
compiler flag,
scalaVersion := "2.9.3"
scalacOptions += "-Ydependent-method-types"
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "1.2.4"
)
This option isn't necessary or supported in Scala 2.10 and later, so you should omit it if you are building with Scala 2.10.2 or later,
scalaVersion := "2.10.4"
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "1.2.4"
)
If you want to be able to support building relative to both 2.9.3 and 2.10 and later then you should use the 2.10.4 configuration above and add the following,
scalacOptions <++= scalaVersion map { version =>
val Some((major, minor)) = CrossVersion.partialVersion(version)
if (major < 2 || (major == 2 && minor < 10))
Seq("-Ydependent-method-types")
else Nil
}
which will set the -Ydependent-method-types
compiler flag conditionally on the actual Scala version in use.
shapeless is built with 0.13.7 or later. SBT 0.13.6 has an issue related to its new name hashing feature which when compiling shapeless causes SBT to loop indefinitely consuming all heap. Workarounds are to move to an earlier or later SBT version or disable name hashing by adding,
incOptions := incOptions.value.withNameHashing(false)
to your settings.
The master of shapeless branch is built with Scala 2.11.4 by default. To build with Scala 2.10.x you should check out the scala-2.10.x branch. As a general rule all new features and bugfixes are made against master and Scala 2.11.4 and merged into the scala-2.10.x branch with only the minimal changes needed for forwards compatibility.
- Alexandre Archambault alexandre.archambault@gmail.com @alxarchambault
- Alois Cochard alois.cochard@gmail.com @aloiscochard
- Ben Hutchison brhutchison@gmail.com @ben_hutchison
- Ben James ben.james@guardian.co.uk @bmjames
- Brian McKenna brian@brianmckenna.org @puffnfresh
- Chris Hodapp clhodapp1@gmail.com @clhodapp
- Cody Allen ceedubs@gmail.com @fourierstrick
- Dario Rexin dario.rexin@r3-tech.de @evonox
- George Leontiev folone@gmail.com @folone
- Huw Giddens hgiddens@gmail.com
- Jason Zaugg jzaugg@gmail.com @retronym
- Johannes Rudolph johannes.rudolph@gmail.com @virtualvoid
- Joni Freeman joni.freeman@ri.fi @jonifreeman
- Julien Tournay boudhevil@gmail.com @skaalf
- Kevin Wright kev.lee.wright@gmail.com @thecoda
- Lars Hupel lars.hupel@mytum.de @larsr_h
- Mathias Doenitz mathias@spray.io @sirthias
- Michael Donaghy md401@srcf.ucam.org
- Michael Pilquist mpilquist@gmail.com @mpilquist
- Miles Sabin miles@milessabin.com @milessabin
- Nikolas Evangelopoulos nikolas@jkl.gr
- Owein Reese owreese@gmail.com @OweinReese
- Paolo G. Giarrusso p.giarrusso@gmail.com @blaisorblade
- Pascal Voitot pascal.voitot.dev@gmail.com @mandubian
- Sam Halliday sam.halliday@gmail.com @fommil
- Stacy Curl stacy.curl@gmail.com @stacycurl
- Stephen Compall scompall@nocandysw.com @S11001001
- Tom Switzer thomas.switzer@gmail.com @tixxit
- Travis Brown travisrobertbrown@gmail.com @travisbrown