May. 30th, 2014

juan_gandhi: (VP)
I just tried this code:

sealed trait Result[+T] {
...
  def <*>[U](other: Result[U]): Result[(T,U)]
...
}
case class Good[T](value:T) extends Result[T] {
...
  def <*>[U](other: Result[U]): Result[(T, U)] = other.flatMap(u => Good((value, u)))
...
}

case class Bad[T](errors:Traversable...) extends Result[T] {
...
  def <*>[U](other: Result[U]): Result[(T, U)] = Bad(errors ++ other.errors)
...
}

scala> val op = Good((1,"one"))
op: Good[(Int, String)] = Good((1,one))

scala> for ((i,s) <- op) println(s"i=$i, s=$s")
i=1, s=one


Why is this important?

See, if I have a class Result[T], and it is applicative, so Result[T] <*> Result[U] produces Result[(T,U)], I want to use the result, naming individual fields. Like in
  val username: Result[String] = getUserNameFromTheCloud(userId)
  val prize:  Result[Prize] = rollTheDice
  
  val letter:Result[(String, Prize)] = for ((u, p) <- username <*> prize) yield congratulate(u, p)
// etc


This is better than having
for(u <- username;
    p <- prize) yield congratulate(u,p)


because in the second case if username is bad, we will never know if prize is bad too; this way we detect only one error. Not so good for fast development. It's like what ancient compilers did.

Questions?
juan_gandhi: (VP)
I have this code:

  lazy val eobOpt: Result[EOB] = ...
  ...

  def items: Result[Traversable[EOB_item]] = {
    val listOfParsedItems: Traversable[Result[EOB_item]] =
      itemsData map {
        item => {
          eobOpt flatMap (buildItem(_)(item))
        }
      }
    Result.traverse(listOfParsedItems).map(_.toList)
  }


Something does not look nice here. flatMap, should not have an alias name, like =>> or something? I can juggle things around, but what I'm looking for is simple beauty, or beautiful simplicity, same thing.

an update

May. 30th, 2014 09:37 pm
juan_gandhi: (VP)
Я тут на днях постил картинку с "хаком от Олега Плисса".

Короче, мне разъяснили забаненные собеседники, что
а) да он матмех закончил, а не какой-то там физфак.
Good for him. Кафедра Матобеспечения, не хуй собачий. (По мне так там э... чему конкретно там учили-то?)
б) Да он вообще, оказывается, живет где-то тут в Санта Кларе и работает в Оракле.

в) и чо?

Ну вы поняли, это обычные питерские разборки, типа кто тут у нас крутой и ваще.

МНЕ ПОФИГ

Але, Куздра, ну я запостил дисклеймер, давай до свидания.

big monad

May. 30th, 2014 09:40 pm
juan_gandhi: (VP)
so, say, we blend List (or Set, or Traversable Once) and Result (or Option, or Either), and define proper monadic multiplication.

For immutables, it will be it, right? No? Of course, for parallel stuff there's continuation, and future; for mutables, it will be state continuation, as Oleg said.

But for this specific small Kleisli category, is not it enough?

Just asking.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

June 2025

S M T W T F S
1 2345 6 7
8 9 10 11 121314
15161718192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 16th, 2025 11:16 am
Powered by Dreamwidth Studios