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

September 2025

S M T W T F S
 1 2345 6
78 9 10 111213
14 151617 181920
21222324252627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 19th, 2025 09:58 am
Powered by Dreamwidth Studios