Mar. 1st, 2013

juan_gandhi: (VP)
Мало того, что они на вебе не отражают реальное состояние - пришедшие деньги они показывают, но если начинаешь пользоваться, то берут овердрафт, потому что их якобы ещё нету; запланированные выплаты показывают как сделанные в день получения, но вычитают на несколько дней раньше - не показывая - и берут овердрафт.

А сегодня обнаружил, что они взяли да закрыли мою карточку, потому что я ей год не пользовался. И сообщили только внутренней мессагой на вебе. Что я зарплату на этот счёт перечисляю, это им пофиг. Радовались бы, что клиент год деньги не снимал.

На хера мне такое обслуживание? Пора мигрировать, блин.
juan_gandhi: (VP)
stackoverflow

1. (Daniel Sobral)
class StringOrInt[T]
object StringOrInt {
  implicit object IntWitness extends StringOrInt[Int]
  implicit object StringWitness extends StringOrInt[String]
}

object Bar {
  def foo[T: StringOrInt](x: T) = x match {
    case _: String => println("str")
    case _: Int => println("int")
  }
}


1', Aaron Novstrup's improvement
sealed trait Or[A, B]

object Or {
   implicit def a2Or[A,B](a: A) = new Or[A, B] {}
   implicit def b2Or[A,B](b: B) = new Or[A, B] {}
}

object Bar {
   def foo[T <% String Or Int](x: T) = x match {
     case _: String => println("str")
     case _: Int => println("int")
   }
}


2. Mile Sabin, using Curry-Howard isomorphism:
type ¬[A] = A => Nothing

//using De Morgan's law this allows him to define union types
type ∨[T, U] = ¬[¬[T] with ¬[U]]

//With the following auxiliary constructs
type ¬¬[A] = ¬[¬[A]]
type |∨|[T, U] = { type λ[X] = ¬¬[X] <:< (T ∨ U) }

//you can write union types as follows:
def size[T : (Int |∨| String)#λ](t : T) = t match {
    case i : Int => i
    case s : String => s.length
}


3. Rex Karr
scala> def f[A](a: A)(implicit ev: (Int with String) <:< A) = a match {
     |   case i: Int => i + 1
     |   case s: String => s.length
     | }
f: [A](a: A)(implicit ev: <:<[Int with String,A])Int

scala> f(3)
res0: Int = 4

scala> f("hello")
res1: Int = 5

scala> f(9.2)
<console>:9: error: Cannot prove that Int with String <:< Double.
       f(9.2)
        ^,


4. Michid's hack
implicit val x: Int = 0
def foo(a: List[Int])(implicit ignore: Int) { }

implicit val y = ""
def foo(a: List[String])(implicit ignore: String) { }

foo(1::2::Nil)
foo("a"::"b"::Nil)

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

August 2025

S M T W T F S
      12
3456789
10 11 12 13141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 14th, 2025 03:19 pm
Powered by Dreamwidth Studios