Oct. 9th, 2011

juan_gandhi: (Default)
here

The idea is to attach specific types to unboxed values, e.g. you have longs as ids, but an id of what? With this trick you can easily tag values, so you won't be able to mix them.

A bonus point is an example of how one can have binary ops on types.
class User
class Checkin
  
type Tagged[U] = { type Tag = U }
type @@[T, U] = T with Tagged[U] // Thanks to @retronym for suggesting this type alias
  
class Tagger[U] {
  def apply[T](t : T) : T @@ U = t.asInstanceOf[T @@ U]
}
def tag[U] = new Tagger[U]

// Manual specialization needed here ... specializing apply above doesn't help
def tag[U](i : Int) : Int @@ U = i.asInstanceOf[Int @@ U]
def tag[U](l : Long) : Long @@ U = l.asInstanceOf[Long @@ U]
def tag[U](d : Double) : Double @@ U = d.asInstanceOf[Double @@ U]

def fetch[A](id: Int @@ A): A = null.asInstanceOf[A]

tweet

Oct. 9th, 2011 01:15 pm
juan_gandhi: (Default)
omg, euler21, I was stuck with a pretty stupid issue, omg
just confessing
juan_gandhi: (Default)
Ответ: а хрен его знает уже... гражданская война так вполне возможна, все вооружены.

Калифорния на этом только выиграет.
juan_gandhi: (Default)
А вот, скажем, у меня многопоточность, и я хочу кешировать вычисления - как это в хаскеле делается-то?
juan_gandhi: (Default)
Можно решить в уме. Я ехал на велике сегодня, решал.

Но сделал ту же ошибку, +-1, что и потом в коде. Тьфу.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

August 2025

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

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 23rd, 2025 12:42 am
Powered by Dreamwidth Studios