implicit-dependent-type, a compiler plugin that resolves dependent types from implicit type classes

16 views
Skip to first unread message

杨博

unread,
Dec 28, 2016, 3:40:53 AM12/28/16
to type...@googlegroups.com, scala...@googlegroups.com

Hi, all,

Recently I published implicit-dependent-type, a compiler plugin that resolves dependent types from implicit type classes.

This plugin provides a syntactic sugar that substitutes all Foo[Bar]##Baz withshapeless.the.`Foo[Bar]`.Baz, which inlines the implicit type class resolving into the type declaration position.

addCompilerPlugin("com.thoughtworks.implicit-dependent-type" %% "implicit-dependent-type" % "1.0.0")
libraryDependencies += "com.chuusai" %% "shapeless" % "2.3.2"

import shapeless._
final case class Foo(bar: Int, baz: String)
val hlistForFoo: Generic[Foo]##Repr = 1 :: "xxx" :: HNil
val foo: Foo = Generic[Foo].from(hlistForFoo)

The above example equals to the following code:

import shapeless._
final case class Foo(bar: Int, baz: String)
val g = Generic[Foo]
val hlistForFoo: g.Repr = 1 :: "xxx" :: HNil
val foo: Foo = Generic[Foo].from(hlistForFoo)

As you see, without this plugin, Generic[Foo] is not a stable value, thus it is unable to inline to a type position. You will have to assign it to a temporary variable g.

Links

Reply all
Reply to author
Forward
0 new messages