Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8137021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:57:11+00:00 2026-06-06T10:57:11+00:00

Even .head doesn’t work. What changes do I need to make to make this

  • 0

Even .head doesn’t work.

What changes do I need to make to make this work?

import shapeless._
import HList._
import Nat._

scala> case class Foo[A](a: A)
defined class Foo

scala> case class Bar[A](f: Foo[A])
defined class Bar

scala> val xs = Foo(23) :: Foo("blah") :: HNil
xs: shapeless.::[Foo[Int],shapeless.::[Foo[java.lang.String],shapeless.HNil]] = Foo(23) :: Foo(blah) :: HNil

scala> object mapper extends (Foo ~> Bar) {
     |   def apply[A](f: Foo[A]) = Bar(f)
     | }
defined module mapper

scala> xs map mapper
res13: mapper.Out = Bar(Foo(23)) :: Bar(Foo(blah)) :: HNil

scala> res13.apply[_1]
<console>:38: error: could not find implicit value for parameter at: shapeless.At[mapper.Out,shapeless.Nat._1]
              res13.apply[_1]
                         ^

scala> res13.head
<console>:38: error: could not find implicit value for parameter c: shapeless.IsHCons[mapper.Out]
              res13.head
                    ^
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T10:57:12+00:00Added an answer on June 6, 2026 at 10:57 am

    Works for me exactly as written, at least with the latest 2.10.0-SNAPSHOT,

    import shapeless._
    import HList._
    import Nat._
    
    scala> case class Foo[A](a: A)
    defined class Foo
    
    scala> case class Bar[A](f: Foo[A])
    defined class Bar
    
    scala> val xs = Foo(23) :: Foo("blah") :: HNil
    xs: shapeless.::[Foo[Int],shapeless.::[Foo[String],shapeless.HNil]] = Foo(23) :: Foo(blah) :: HNil                                                                                                     
    
    scala> object mapper extends (Foo ~> Bar) {
         |   def apply[A](f: Foo[A]) = Bar(f)                                                                                                                                                              
         | }                                                                                                                                                                                               
    defined module mapper                                                                                                                                                                                  
    
    scala> xs map mapper                                                                                                                                                                                   
    res0: shapeless.::[Bar[Int],shapeless.::[Bar[String],shapeless.HNil]] = Bar(Foo(23)) :: Bar(Foo(blah)) :: HNil                                                                                         
    
    scala> res0[_1]
    res1: Bar[String] = Bar(Foo(blah))                                                                                                                                                                     
    
    scala> res0.head                                                                                                                                                                                       
    res2: Bar[Int] = Bar(Foo(23))
    

    Notice that the type inferred for res0 above is Bar[Int] :: Bar[String] :: HNil rather than mapper.Out … I suspect that this is a difference in behaviour between 2.9.x and 2.10.0-SNAPSHOT.

    If you’re stuck with 2.9.x then I think you should be able to work around the problem by ascribing Bar[Int] :: Bar[String] :: HNil to your res13 explicitly … obviously that’s more verbose, but c’est la vie.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This doesn't work in D: void doSomething(auto a, auto b){ // ... } I'm
I've been scratching my head on this one even though it shouldn't be so
Alrighty guys, I got myself in over my head at my internship. Even my
Even though it's a valid method, JComboBox#setVisible doesn't hide my JComboBox . Am I
Even Stack Overflow doesn't compress their HTML . Is it recommended to compress HTML?
Im making a collision checking system with jQuery however it doesn't seem to work.
Forgive a newbie, I don't even know how to ask this question properly: I
Having a bit of trouble wrapping my head around Qtimer this morning. Here's the
I have this asp.NET web site that for some odd reason doesn't want to
I think this has been asked before but even though I searched Google I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.