Sep. 12th, 2013

О! ... ?

Sep. 12th, 2013 09:03 am
xacid: (Default)
object o_O extends App {

  import shapeless._, ops.coproduct._

  type ** = Int :+: String :+: Boolean :+: CNil

  implicit def *>[?](x: ?)(implicit %% : ** Inject ?) = %%(x)

  def ?=>(x: **) = x unify match {
    case n: Int => n
    case s: String => s.length
    case b: Boolean => if (b) 1 else 0
  }

  def +?(x: (**)*) = x map ?=> reduce (_ + _)

  // +?(1,"hello", true, 2.0)
  // Compiler forbids: Wrong type: 2.0 : Double

  println {

     +?(1, "hello", true)) // 7

  }

}

Profile

xacid: (Default)
xacid

April 2021

S M T W T F S
    123
45678910
11121314151617
18192021222324
252627282930 

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 21st, 2025 05:34 am
Powered by Dreamwidth Studios