problem with implicit ambiguity between my method and conforms in Predef

后端 未结 2 341
情话喂你
情话喂你 2020-12-20 02:06

The following code, which is taken from Apocalisp\'s excellent blog series: Type level programming in scala , and modified for an implicit parsing scenario. However, this d

2条回答
  •  隐瞒了意图╮
    2020-12-20 03:02

    Although i can't tell you exactly the purpose of Predef.conforms, i can tell you the ambiguity error seems correct (unfortunately). In the comment in the source it even says that <:< was introduced because of ambiguity problems of Function1 (says Function2 but i guess that is a mistake). But since <:< is a subclass of Function1 it can be passed in whenever Function1 is expected, so in your case its possible to pass in <:< to hparse.

    Now the implicit def conforms[A]: A <:< A has the effect (from what i understand) that whenever a method expects a type A => A, it is sufficient to have an implicit value of A in scope.

    In your case the implicit def hParseNil: HNil => HNil has the same priority as conforms and thus both could be equally applied.

    I see two possible solutions:

    • just remove the hParseNil, i think your code still works.
    • shadow the Predef's conforms by naming yours the same:

      implicit def conforms: HNil => HNil = _ => new HNil

提交回复
热议问题