type lambda woes

145 views
Skip to first unread message

Matthew Pocock

unread,
Feb 25, 2015, 11:59:49 AM2/25/15
to scala-user
Hi,

I am having a problem with type lambdas. I'm using shapeless hlists, and am trying to infer an hlist of functions to some type X from an hlist of argument types. For some reason, scalac isn't unifying the lambda I have over functions.

type sx[T] = T => String
implicitly[Mapped[HNil, sx]]
This variant works fine. However, this one doesn't work:

trait fx[X] {
type λ[T] = T => X
}
implicitly[Mapped[HNil, fx[String]#λ]]
When I log implicits, I get:

[info] /home/nmrp3/devel/oss/xsd/src/main/scala/w3c/tests/CasterTest.scala:59: hlist.this.Mapped.hnilMapped is not a valid implicit value for shapeless.ops.hlist.Mapped[shapeless.HNil,[T]T => String] because:
[info] hasMatchingSymbol reported error: polymorphic expression cannot be instantiated to expected type;
[info]  found   : [F[_]]shapeless.ops.hlist.Mapped.Aux[shapeless.HNil,F,shapeless.HNil]
[info]     (which expands to)  [F[_]]shapeless.ops.hlist.Mapped[shapeless.HNil,F]{type Out = shapeless.HNil}
[info]  required: shapeless.ops.hlist.Mapped[shapeless.HNil,[T]T => String]
[info]     implicitly[Mapped[HNil, fx[String]#λ]]

It looks like the type lambda, bound to the T=>String type isn't getting lifted out to the whole expression to a T[_] prefix.

I can't see any reason why this should not work in principle. I've got a type of the right kind. fx[String]#λ is, for some definition of equivalent, equivalent to sx.

Have I hit a compiler bug, or am I missing something?

Matthew

--
Dr Matthew Pocock
Turing ate my hamster LTD

Integrative Bioinformatics Group, School of Computing Science, Newcastle University

skype: matthew.pocock
tel: (0191) 2566550

Jason Zaugg

unread,
Feb 25, 2015, 7:57:52 PM2/25/15
to Matthew Pocock, scala-user
On Thu, Feb 26, 2015 at 2:59 AM, Matthew Pocock <turingate...@gmail.com> wrote:
Hi,

I am having a problem with type lambdas. I'm using shapeless hlists, and am trying to infer an hlist of functions to some type X from an hlist of argument types. For some reason, scalac isn't unifying the lambda I have over functions.

Hi Matthew,

I’ve distilled the problem a little and added an explanation of why inference fails in the second case in the comments of this gist:

tl;dr The type fx[String]#λ is reduced to a polymorphic type [T] T =>String, which means the subsequent attempt to infer the type parameter F fails due to the lack of higher order unification.

-jason

Reply all
Reply to author
Forward
0 new messages