Skip to content
Oeiuwq Faith Blog OpenSource Porfolio

milessabin/shapeless

Generic programming for Scala

milessabin/shapeless.json
{
"createdAt": "2011-12-18T13:36:38Z",
"defaultBranch": "main",
"description": "Generic programming for Scala",
"fullName": "milessabin/shapeless",
"homepage": "",
"language": "Scala",
"name": "shapeless",
"pushedAt": "2025-10-14T08:15:35Z",
"stargazersCount": 3402,
"topics": [
"fp",
"functional-programming",
"generic-programming",
"scala",
"typelevel"
],
"updatedAt": "2025-11-12T00:34:04Z",
"url": "https://github.com/milessabin/shapeless"
}

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][milessabin]), given over the course of 2011, on implementing [scrap your boilerplate][syb] and [higher rank polymorphism][higherrank] in Scala. Since then it has evolved from being a resolutely experimental project into a 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.

Discord Gitter Maven Central Scala.js

There is a wide variety of projects which use shapeless in one way or another … see the [incomplete list of projects][built-with-shapeless] for ideas and inspiration. If you are using shapeless and your project isn’t listed yet, please add it.

[built-with-shapeless] !: https://github.com/milessabin/shapeless/wiki/Built-with-shapeless

The [feature overview for shapeless-2.0.0][features200] provides a very incomplete introduction to shapeless. Additional information can be found in subsequent [release notes][relnotes220]. If you are upgrading from shapeless-2.0.0 you will find the [migration guide][migration210] 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][typelevel] family of projects. It is an Open Source project under the Apache License v2, hosted on [github][source]. Binary artefacts are published to the [Sonatype OSS Repository Hosting service][sonatype] and synced to Maven Central.

Most discussion of shapeless and generic programming in Scala happens on the #shapless channel of the [Typelevel Discord][discord]. There is also a [mailing list][group] and [Gitter][gitter], but these are largely dormant now that most activity has moved to Discord. Questions about shapeless are often asked and answered under the [shapeless tag on StackOverflow][so]. Some articles on the implementation techniques can be found on [Miles’s blog][blog], and Olivera, Moors and Odersky, [Type Classes as Object and Implicits][tcoi] is useful background material.

[features200] !: https://github.com/milessabin/shapeless/wiki/Feature-overview:-shapeless-2.0.0 [relnotes] !: https://github.com/milessabin/shapeless/wiki/Release-notes:-shapeless-2.0.0 [relnotes220] !: https://github.com/milessabin/shapeless/wiki/Release-notes:-shapeless-2.2.0 [migration] !: https://github.com/milessabin/shapeless/wiki/Migration-guide:-shapeless-1.2.4-to-2.0.0 [migration210] !: https://github.com/milessabin/shapeless/wiki/Migration-guide:-shapeless-2.0.0-to-2.1.0 [milessabin] !: https://twitter.com/milessabin [syb] !: https://www.microsoft.com/en-us/research/publication/scrap-your-boilerplate-with-class/ [higherrank] !: http://homes.sice.indiana.edu/ccshan/cs252/usage.pdf [typelevel] !: http://typelevel.org/ [scalaz] !: https://github.com/scalaz/scalaz [spire] !: https://github.com/non/spire [tcoi] !: http://ropas.snu.ac.kr/~bruno/papers/TypeClasses.pdf [source] !: https://github.com/milessabin/shapeless [sonatype] !: https://oss.sonatype.org/index.html#nexus-search;quick~shapeless [wiki] !: https://github.com/milessabin/shapeless/wiki [group] !: https://groups.google.com/group/typelevel [so] !: http://stackoverflow.com/questions/tagged/shapeless [gitter] !: https://gitter.im/milessabin/shapeless [discord] !: https://discord.gg/bSQBZA3Ced [irc] !: http://webchat.freenode.net?channels=%23shapeless [blog] !: http://milessabin.com/blog

The shapeless project supports the [Typelevel Code of Conduct][codeofconduct] 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 #shapeless [Discord channel][discord], 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][goodfirstissue]. No contribution is too small, and guidance is always available.

[codeofconduct] !: https://typelevel.org/code-of-conduct.html [goodfirstissue] !: https://github.com/milessabin/shapeless/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22

Binary release artefacts are published to the [Sonatype OSS Repository Hosting service][sonatype] and synced to Maven Central. Snapshots of the main branch are built using GitHub actions and automatically published to the Sonatype OSS Snapshot repository.

Try shapeless with an Ammonite instant REPL

Section titled “Try shapeless with an Ammonite instant REPL”

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”][try-shapeless] script, which has no dependencies other than an installed JDK. This script downloads and installs [coursier][coursier] and uses it to fetch the [Ammonite][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/main/scripts/try-shapeless.sh | bash
Loading...
Compiling (synthetic)/ammonite/predef/interpBridge.sc
Compiling (synthetic)/ammonite/predef/replBridge.sc
Compiling (synthetic)/ammonite/predef/DefaultPredef.sc
Compiling /home/miles/projects/shapeless/(console)
Welcome to the Ammonite Repl 1.6.8
(Scala 2.13.1 Java 1.8.0_212)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@ 23 :: "foo" :: true :: HNil
res0: Int :: String :: Boolean :: HNil = 23 :: "foo" :: true :: HNil
@ Bye!
%

[try-shapeless] !: https://github.com/milessabin/shapeless/blob/main/scripts/try-shapeless.sh [coursier] !: https://github.com/coursier/coursier [ammonite] !: https://github.com/com-lihaoyi/Ammonite

To include the Sonatype repositories in your SBT build you should add,

resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
)

[ci] !: https://travis-ci.org/milessabin/shapeless

Builds are available for Scala 2.11.x, 2.12.x and 2.13.x. The main line of development for shapeless 2.3.3 is Scala 2.13.2.

scalaVersion := "2.13.5"
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.3.3"
)

For using snapshots of Shapeless you should add,

scalaVersion := "2.13.5"
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.4.0-SNAPSHOT"
)

shapeless is also available for projects using the Maven build tool via the following dependency,

<dependency>
<groupId>com.chuusai</groupId>
<artifactId>shapeless_2.13</artifactId>
<version>2.3.3</version>
</dependency>

Please use a current release if possible. If unavoidable, you can find [usage information for older releases][olderusage] on the shapeless wiki.

[olderusage] !: https://github.com/milessabin/shapeless/wiki/Using-shapeless:-older-releases

shapeless is built with SBT 1.3.10 or later, and its main branch is built with Scala 2.13.2 by default but also cross-builds for 2.11.12 and 2.12.12.

[namehashing] !: https://github.com/sbt/sbt/issues/1640