Skip to content

no type arguments for views?Β #37

@benmccann

Description

@benmccann

@refried originally filed as playframework/playframework#2194. migrating it here

views/foo1.scala.txt (won't compile)

@[L<:shapeless.Nat:shapeless.ops.nat.ToInt](bar: Bar[L])

@bar has size @shapeless.Nat.toInt[L]

views/foo2.scala.txt (will compile, but silly!)

@(bar: Bar[_<:shapeless.Nat], size: Int)

@bar has size @size

controllers/Application.scala

package controllers

import play.api._
import play.api.mvc._
import shapeless.Nat
import shapeless.ops.nat.ToInt

class Bar[L<:Nat]

object Application extends Controller {

  def index = Action {
    Ok(views.html.index("Your new application is ready."))
  }

  // won't compile
  def foo1 = views.txt.foo1(new Bar[Nat._3])

  // needlessly complicated
  def foo2 = {
    def barSize[L<:Nat:ToInt](bar: Bar[L]): Int = Nat.toInt[L]
    val bar = new Bar[Nat._3]
    val size = barSize(bar)
    views.txt.foo2(bar, size)
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions