juan_gandhi: (Default)
I'm pretty much tired of using so-called "DAO objects", automatically hibernate-generated classes that are dumb and simple; they are being used everywhere throughout the code; I was always willing to fill them with functionality, but, thank god, there was no chance.

Now I think this. Thanks to [livejournal.com profile] mikkim08 ideas for Scala. They should be all wrapped in decorators; and decorators should be returned from DAOs or factories. Performance-wise, it is just one level of indirection, and one more reference per instance. Conceptually, it is an implicit mapping.

E.g. I get "CountryData" from db; it is dumb and know nothing about life, just data. Wrap it in a subclass, and kaboom, an intelligent guy who can tell you this and that... and yes, immutable, since all "setters" are blocked by police.

So there.
juan_gandhi: (Default)
is not with algorithms; there's hardly any algorithm that is hard to implement, once it's clearly formulated.
And it is probably not even performance, since it is another algorithm issue.

It is our struggle with monads. With monads that don't commute.

That's what makes Haskell so good (and so hard): it makes us to mention monads explicitly.
juan_gandhi: (Default)
Until I was told to take a look at coalgebras, and figured out that input deals with codata, and output deals with data, and that StringReader consists of mapping an algebra to a coalgebra, over the same affine functor, X -> AX + 1, I could not figure out how to properly connect my binary files with parser combinators... and the whole functioning of parser combinators in general.

The main point is that parser combinators work not on data, but on codata. So there.
juan_gandhi: (Default)
Just found that there are some questions for which I cannot find answers... hello, anybody? Not that I did not open Abadi/Cardelli, or Moggi, or Uustalo... just looking for simple answers, if there are any.


  • What is the right way of expressing, functionally, via monads most probably, parser combinators? Is it just a special case of state monad?

  • We can discuss the ellipse/circle OOP paradox ad libitum, but my question is: how do we know it this class, called Ellipse and having 4 members, is actually an ellipse? Not just four numbers, not a point in R4, but an ellipse? There's nothing in the definition that makes it an ellipse; there's nothing that makes it different from a rectangle. So the question could be, is Ellipse a Rectangle? Is Square a Circle? (And why not, from OOP point of view)

  • What is a mutable class, or a mutable class member, from, hmm, a mathematical, say, categorical p.o.v.? A function? A generalized point? The last one would be a cool answer... I mean, I can build immutable classes from primitive types using pullbacks in a category with pullbacks and pushouts, but how about mutables? Clueless, kind of.

juan_gandhi: (Default)
  def bytes(is: InputStream) : Iterator[Byte] = new Iterator[Byte] {
    def hasNext = is.available > 0
    def next = is.read.toByte

  def isText(b: Byte) = b == 0x0a || b == 0x0d || b >= 32 && b < 0xff

  def chars(is: InputStream) = bytes(is) filter isText map (_.toChar)



So that I can use it like this:
  def main(args: Array[String]) {
    val is = new FileInputStream(args(0))
    for (c <- chars(is)) print(c)
  }


(that's monadic, kind of)
juan_gandhi: (Default)
So, I got tomcat running in the cloud. And it turned out I do not need Sun's java; the opensource or whatever there is is enough.

I actually do not even need an s3. Will pipe through my website:
- an ftp script on my laptop that sends a new .war file if there's any;
- an ftp script on the ec2 instance that will pull the .war and deploys it in tomcat;

Probably just one question left, how to translate 80→8080; the suggested solution somehow did not work. Oh, whatever, it's not the most important. Just make it work.
juan_gandhi: (Default)
object closable {
  type Closable = { def close }
  class Autoclose[A <: Closable](c: A){
    def foreach(f: A => Unit) = {
      try { f(c) }finally { c.close }
    }
  }
  implicit def autoClosable[A <: Closable](c: A) = new Autoclose(c)
//...
  case class Connection(name:String) {
    def close = println("closing " + this) 
  }
  case class Statement(c: Connection,q :String){
    def close = println("closing " + this)
    def exec = println("executing " + q + " on " + c)
  }
  def test = for(c <- Connection("conn"); 
		 st <- Statement(c,"select * from table")){
		   st.exec
		 }
}


[livejournal.com profile] _navi_, I remember you were talking about something like this

(src 10x Ramzi ben Yahia).

web shell

Dec. 7th, 2010 05:58 pm
juan_gandhi: (Default)
When I wrote it about 8 years ago, I could never guess that I'd need it later on. Now it is a tool without which I could not do anything. Feeling like will have to work on it, turn it into something more useful.

What I'm currently trying to do now, is build latex from sources (already rsync'd) on the server I renor t for $10/mo, where all I have is the opportunity to upload a war and run my servlets or jsps. Being lazy, I prefer jsps... except for my app which I wrote in Scala... but Scala is not very far from jsp actually.
juan_gandhi: (Default)
frpog#5/F#:

Конвейерные операторы — передают значение, вычисленное одной функцией, на вход второй. Пожалуй, наиболее часто употребляемым оператором из этой группы можно назвать |>, определение которого выглядит так:
let (|>) x f = f x

Казалось бы, ничего сверхъестественного — лишь простая перестановка местами функции и её аргумента. Но это может быть очень удобно в случае, когда необходимо последовательно совершить несколько преобразований над одним исходным значением, например, списком:
let list = [1..10]
list
  |> List.map (fun i -> i*i)
  |> List.iter (fun sq -> printfn "Square: %d" sq)


Классная идейка-то. Как-то в скале не популяризуется; надо будет попробовать. Не знал раньше.
juan_gandhi: (Default)
Running unix commands from scala...

Read more... )
juan_gandhi: (Default)
In short, I came to a conclusion that while lift is the best technology for a web app, it is not worth it for a web page. E.g. I just want a service that takes a query, returns a response. Functionality inside. Why would I need lift with forms, session tracking, etc? I'll just use servlets, and will write them in Scala, and that would be it.

Update. Oh, okay, can go to sleep. Unlike lift... just got tomcat, got all the stuff from Burak Emir, configured ant.properties, fixed one line in Burak's code dating 2007 (ancient history, by Scala scale) - and lo and behold, have a .war file, deployed it, and it runs.

Small joys.

(Among other events, my check was bounced by my bank. First time in my life. Had to write an email to the artist to whom I wrote the check... in short, hope he'll join our barbecue tomorrow...)
juan_gandhi: (Default)
вот
Requires full projector screen

codecamp link

Critique welcome.

P.S. If you are on mac, pls ignore the error message re: graphics. There's no graphics.
juan_gandhi: (Default)
  val FINITE_SETS: BigSet = bigset((o: Set[_]) => o.size < Integer.MAX_VALUE)

  ...

  test("Setf should not not contain NNO") {
    assert(!(FINITE_SETS contains N))
  }

  test("Setf should not contain itself") {
    assert(!(FINITE_SETS contains FINITE_SETS))
  }

  test("Setf should contain various finite sets") {
    assert(FINITE_SETS contains Set[String]())
    assert(FINITE_SETS contains Set("infinity"))
    assert(FINITE_SETS contains Set(1,2,3,42))
  }

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

November 2025

S M T W T F S
       1
23456 7 8
9 1011 12 1314 15
16171819 20 2122
23 24 252627 28 29
30      

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 1st, 2025 10:19 am
Powered by Dreamwidth Studios