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.
There is a wide variety of projects which use shapeless in one way or another ... see the incomplete list of projects for ideas and inspiration. If you are using shapeless and your project isn't listed yet, please add it.
The feature overview for shapeless-2.0.0 provides a very incomplete introduction to shapeless. Additional information can be found in subsequent release notes. If you are upgrading from shapeless-2.0.0 you will find the migration guide useful. We're not satisfied with the current state of the documentation and would love help in improving it. You can find an excellent guide to Shapeless here: The Type Astronaut's Guide to Shapeless.
shapeless is part of the Typelevel family of projects. 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.
Most discussion of shapeless and generic programming in Scala happens on the shapeless Gitter channel. There is also a mailing list and IRC channel, but these are largely dormant now that most activity has moved to Gitter. 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.
The shapeless project supports the Typelevel code of conduct and wants all of its channels (mailing list, Gitter, 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 the Gitter channel, 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 branch are built using Travis CI and automatically published to the Sonatype OSS Snapshot repository.
The quickest way to get to a REPL prompt with the latest version of shapeless on the class path is to run the provided "try shapeless" script, which has no dependencies other than an installed JDK. This script downloads and installs coursier and uses it to fetch the Ammonite REPL and the latest version of shapeless. It then drops you immediately into a REPL session,
% curl -s https://raw.githubusercontent.com/milessabin/shapeless/master/scripts/try-shapeless.sh | bash
Loading...
Welcome to the Ammonite Repl 0.8.2
(Scala 2.11.8 Java 1.8.0_102)
@ 23 :: "foo" :: true :: HNil
res0: Int :: String :: Boolean :: HNil = 23 :: foo :: true :: HNil
@ Bye!
%
To include the Sonatype repositories in your SBT build you should add,
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
)
Builds are available for Scala 2.10.x, 2.11.x and for 2.12.x. The main line of development for shapeless 2.3.2 is Scala 2.12.3. Scala 2.10.x is supported via the macro paradise compiler plugin.
scalaVersion := "2.12.3"
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.3.2"
)
If you are using Scala 2.10.x, you should also add the macro paradise plugin to your build,
scalaVersion := "2.10.6"
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.3.2",
compilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)
)
Typelevel Scala provides a partial fix for SI-7046 which can present obstacles to using
shapeless's Generic
and LabelledGeneric
for the sealed trait at the root of an ADT. If it appears that these two
type classes are unable to find (all of) the subclasses of the root trait then please try using Typelevel Scala and
see if it resolves the issue.
To use Typelevel Scala you should,
-
Update your
project/build.properties
to require SBT 0.13.13 or later,sbt.version=0.13.13
-
Add the following to your
build.sbt
immediately next to where you setscalaVersion
,scalaOrganization := "org.typelevel"
If this does resolve the problem, please lend your support to the pull request being merged in Lightbend Scala.
shapeless is also available for projects using the Maven build tool via the following dependency,
<dependency>
<groupId>com.chuusai</groupId>
<artifactId>shapeless_2.11</artifactId>
<version>2.3.2</version>
</dependency>
If you are using Scala 2.10.x, you should also add the macro paradise plugin to your build,
<dependency>
<groupId>com.chuusai</groupId>
<artifactId>shapeless_2.10</artifactId>
<version>2.2.5</version>
</dependency>
<plugins>
...
<plugin>
...
<configuration>
...
<compilerPlugins>
<compilerPlugin>
<groupId>org.scala-lang.plugins</groupId>
<artifactId>macro-paradise_2.10</artifactId>
<version>2.1.0</version>
</compilerPlugin>
</compilerPlugins>
...
</configuration>
...
</plugin>
...
</plugins>
Please use a current release if possible. If unavoidable, you can find usage information for older releases on the shapeless wiki.
shapeless is built with SBT 0.13.13 or later, and its master branch is built with Scala 2.12.3 by default but also cross-builds for 2.10.6 and 2.11.8.
- Alessandro Lacava [email protected] @lambdista
- Alexander Konovalov [email protected] @alexknvl
- Alexandre Archambault [email protected] @alxarchambault
- Alistair Johnson [email protected] @AlistairUSM
- Alois Cochard [email protected] @aloiscochard
- Andreas Koestler [email protected] @AndreasKostler
- Andrew Brett [email protected] @Ephemerix
- Arya Irani [email protected] @aryairani
- Ben Hutchison [email protected] @ben_hutchison
- Ben James [email protected] @bmjames
- Brian McKenna [email protected] @puffnfresh
- Brian Zeligson [email protected] @beezee
- Bryn Keller [email protected] @brynkeller
- Chris Hodapp [email protected] @clhodapp
- Cody Allen [email protected] @fourierstrick
- Dale Wijnand [email protected] @dwijnand
- Daniel Urban [email protected]
- Dario Rexin [email protected] @evonox
- Dave Gurnell [email protected] @davegurnell
- David Barri [email protected] @japgolly
- Denis Mikhaylov [email protected] @notxcain
- Eugene Burmako [email protected] @xeno_by
- Filipe Nepomuceno [email protected]
- Frank S. Thomas [email protected] @fst9000
- George Leontiev [email protected] @folone
- Georgi Krastev [email protected] @Joro_Kr
- Hamish Dickenson [email protected] @hamishdickson
- Howard Branch [email protected] @purestgreen
- Huw Giddens [email protected]
- Ievgen Garkusha [email protected]
- Jason Zaugg [email protected] @retronym
- Jean-Remi Desjardins [email protected] @jrdesjardins
- Jeff Wilde [email protected]
- Jeremy R. Smith [email protected] @jeremyrsmith
- Jisoo Park [email protected] @guersam
- Johannes Rudolph [email protected] @virtualvoid
- Johnny Everson [email protected] @johnny_everson
- Jolse Maginnis [email protected] @doolse2
- Joni Freeman [email protected] @jonifreeman
- Joseph Price [email protected]
- Juan José Vázquez Delgado [email protected] @juanjovazquez
- Julien Tournay [email protected] @skaalf
- Jules Gosnell [email protected]
- Kailuo Wang [email protected] @kailuowang
- Kenji Yoshida [email protected] @xuwei_k
- Kevin Wright [email protected] @thecoda
- Lars Hupel [email protected] @larsr_h
- Mario Pastorelli [email protected] @mapastr
- Matthew Taylor [email protected]
- Mathias Doenitz [email protected] @sirthias
- Michael Donaghy [email protected]
- Michael Pilquist [email protected] @mpilquist
- Miles Sabin [email protected] @milessabin
- Neville Li [email protected] @sinisa_lyh
- Nikolas Evangelopoulos [email protected]
- Oleg Aleshko [email protected] @OlegYch
- Olivier Blanvillain [email protected]
- Olli Helenius [email protected] @ollijh
- Owein Reese [email protected] @OweinReese
- Paolo G. Giarrusso [email protected] @blaisorblade
- Pascal Voitot [email protected] @mandubian
- Pavel Chlupacek [email protected] @pacmanius
- Peter Neyens [email protected] @pneyens
- Peter Schmitz [email protected] @peterschmitz_
- Renato Cavalcanti [email protected] @renatocaval
- Rob Norris [email protected] @tpolecat
- Robert Hensing [email protected]
- Ryo Hongo [email protected] @ryoppy516
- Sam Halliday [email protected] @fommil
- Sarah Gerweck [email protected] @SGerweck
- Sébastien Doeraene [email protected] @sjrdoeraene
- Simon Hafner [email protected] @reactormonk
- Stacy Curl [email protected] @stacycurl
- Stephen Compall [email protected] @S11001001
- Tin Pavlinic [email protected] @triggerNZ
- Tom Switzer [email protected] @tixxit
- Tomas Mikula [email protected] @tomas_mikula
- Travis Brown [email protected] @travisbrown
- Valentin Kasas [email protected] @ValentinKasas
- Valerian Barbot [email protected] @etaty
- Vladimir Matveev [email protected] @netvlm
- Vladimir Pavkin [email protected] @vlpavkin
- Yang Bo (杨博) [email protected] @Atry