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.
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. This downloads and installs coursier and uses it to fetch the Ammonite REPL and the latest version of shapeless and drops you immediately into a REPL session to play around with,
miles@frege:shapeless (master)$ scripts/try-shapeless.sh
Loading...
Welcome to the Ammonite Repl 0.5.8
(Scala 2.11.8 Java 1.8.0_51)
@ 1 :: "foo" :: true :: HNil
res0: Int :: String :: Boolean :: HNil = 1 :: foo :: true :: HNil
@
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.0-M4. The main line of development for shapeless 2.3.1 is Scala 2.11.8 with Scala 2.10.x supported via the macro paradise compiler plugin.
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.3.1"
)
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.1",
compilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)
)
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.1</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 be aware that SBT 0.13.6 has an issue related to its name hashing feature which when compiling with shapeless might cause SBT to loop indefinitely consuming all heap. If possible move to a more recent version of SBT. If you must use SBT 0.13.6 a workaround is to disable name hashing by adding,
incOptions := incOptions.value.withNameHashing(false)
to your settings.
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.11 or later, and its master branch is built with Scala 2.11.8 by default but also cross-builds for 2.10.6 and 2.12.x.
- Alessandro Lacava alessandrolacava@gmail.com @lambdista
- Alexander Konovalov alex.knvl@gmail.com @alexknvl
- Alexandre Archambault alexandre.archambault@gmail.com @alxarchambault
- Alistair Johnson alistair.johnson@johnsonusm.com @AlistairUSM
- Alois Cochard alois.cochard@gmail.com @aloiscochard
- Andreas Koestler andreas.koestler@gmail.com @AndreasKostler
- Andrew Brett github@bretts.org @Ephemerix
- Arya Irani arya.irani@gmail.com @aryairani
- Ben Hutchison brhutchison@gmail.com @ben_hutchison
- Ben James ben.james@guardian.co.uk @bmjames
- Brian McKenna brian@brianmckenna.org @puffnfresh
- Brian Zeligson brian.zeligson@gmail.com @beezee
- Bryn Keller xoltar@xoltar.org @brynkeller
- Chris Hodapp clhodapp1@gmail.com @clhodapp
- Cody Allen ceedubs@gmail.com @fourierstrick
- Dale Wijnand dale.wijnand@gmail.com @dwijnand
- Daniel Urban urban.dani@gmail.com
- Dario Rexin dario.rexin@r3-tech.de @evonox
- Dave Gurnell d.j.gurnell@gmail.com @davegurnell
- David Barri japgolly@gmail.com @japgolly
- Denis Mikhaylov notxcain@gmail.com @notxcain
- Eugene Burmako xeno.by@gmail.com @xeno_by
- Filipe Nepomuceno filinep@gmail.com
- Frank S. Thomas frank@timepit.eu @fst9000
- George Leontiev folone@gmail.com @folone
- Hamish Dickenson hamish.dickson@gmail.com @hamishdickson
- Howard Branch purestgreen@gmail.com @purestgreen
- Huw Giddens hgiddens@gmail.com
- Ievgen Garkusha ievgen@riskident.com
- Jason Zaugg jzaugg@gmail.com @retronym
- Jean-Remi Desjardins jeanremi.desjardins@gmail.com @jrdesjardins
- Jeff Wilde jeff@robo.ai
- Jisoo Park xxxyel@gmail.com @guersam
- Johannes Rudolph johannes.rudolph@gmail.com @virtualvoid
- Johnny Everson khronnuz@gmail.com @johnny_everson
- Joni Freeman joni.freeman@ri.fi @jonifreeman
- Joseph Price josephprice@iheartmedia.com
- Julien Tournay boudhevil@gmail.com @skaalf
- Jules Gosnell jules_gosnell@yahoo.com
- Kailuo Wang kailuo.wang@gmail.com @kailuowang
- Kenji Yoshida 6b656e6a69@gmail.com @xuwei_k
- Kevin Wright kev.lee.wright@gmail.com @thecoda
- Lars Hupel lars.hupel@mytum.de @larsr_h
- Mario Pastorelli mario.pastorelli@teralytics.ch @mapastr
- Matthew Taylor matthew.t@tbfe.net
- Mathias Doenitz mathias@spray.io @sirthias
- Michael Donaghy md401@srcf.ucam.org
- Michael Pilquist mpilquist@gmail.com @mpilquist
- Miles Sabin miles@milessabin.com @milessabin
- Neville Li neville@spotify.com @sinisa_lyh
- Nikolas Evangelopoulos nikolas@jkl.gr
- Oleg Aleshko olegych@tut.by @OlegYch
- Olivier Blanvillain olivier.blanvillain@gmail.com
- Olli Helenius liff@iki.fi @ollijh
- Owein Reese owreese@gmail.com @OweinReese
- Paolo G. Giarrusso p.giarrusso@gmail.com @blaisorblade
- Pascal Voitot pascal.voitot.dev@gmail.com @mandubian
- Pavel Chlupacek pavel.chlupacek@spinoco.com @pacmanius
- Peter Neyens peter.neyens@gmail.com @pneyens
- Peter Schmitz petrischmitz@gmail.com @peterschmitz_
- Renato Cavalcanti renato@strongtyped.io @renatocaval
- Rob Norris rob_norris@mac.com @tpolecat
- Robert Hensing spam@roberthensing.nl
- Ryo Hongo ryoppy0516@gmail.com @ryoppy516
- Sam Halliday sam.halliday@gmail.com @fommil
- Sarah Gerweck sarah.a180@gmail.com @SGerweck
- Sébastien Doeraene sjrdoeraene@gmail.com @sjrdoeraene
- Simon Hafner hafnersimon@gmail.com @reactormonk
- Stacy Curl stacy.curl@gmail.com @stacycurl
- Stephen Compall scompall@nocandysw.com @S11001001
- Tin Pavlinic tin.pavlinic@gmail.com @triggerNZ
- Tom Switzer thomas.switzer@gmail.com @tixxit
- Tomas Mikula tomas.mikula@gmail.com @tomas_mikula
- Travis Brown travisrobertbrown@gmail.com @travisbrown
- Valentin Kasas valentin.kasas@gmail.com @ValentinKasas
- Valerian Barbot valerian.barbot@onzo.com @etaty
- Vladimir Matveev vladimir.matweev@gmail.com @netvlm
- Vladimir Pavkin vpavkin@gmail.com @vlpavkin