scala - Type inference on contents of shapeless HList -


This example is simplified.

I have a set of such classes:

  Case class keymapping [kytype] (k: key type) class wrapped mapping [ketipe] (m: t some { Type T   

The following types of code are guessed correctly: < Pre> val w = new raped mapping (keymapping ("key") // the following statement true error // type mismatch; // found: wktype (with the built-in type string) required: nothing / val test1 : Nothing = wk

I have no clue how to guess the right type for the following types:

  class mappings [ketipe, l & Lt;: HList] (Mapping: L) {val k: KeyType = ???} Val m = New mapping (keymapping ("key 1") :: main mapping ("key 2") :: HNIL) Should not be compiled, the string string should be of test2: nothing = mk   

what HList

keytype "Post-T based on the contents of

Ext "itemprop =" text ">

provides a built-in toList that is used to convert HLists to lists, is inauspicious.

To do this, the first HList should calculate those types of ELUB (at least upper bounds), and something that you can use:

 < Code> imported useless .ops.hlist.ToList class mapping [l & lt; : HList, Lub] (Mapping: L) (List: ToList [L, Lub]) goes to {...}   

L , the built-in resolution Drag out of the L , lab type, which blocks a (and only) valid toList example.

This is not enough, however, as the lab will be the keymap [string] , whereas what you want is string is part. To be shapeless in general, the solution is to add another underlying:

  class mapping [L & lt;: HList, Lub, KeyType] (Mapping: L) (Built-in for list Val: ToList [L, Lib], Val Katie: Lub & Lt ;: & lt; Keymapping [Keytype]] {val k: keytype = null.asInstanceOf [KeyType]}   

( There is no need to be implicits val s, but if you are looking for things in RPL, then it helps)

What is the emphasis that lob In this way KeyMapping [KeyType] (like it's a subtype or exact same type) , where KeyType is still unknown. Then, there is a valid solution for only the specified values, and the keytype parameter is drawn as a string .

I do not know how you plan to implement k , but you think that being a tolist example will help you This will help because it gives you the mappings.toList

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -