switch to room list switch to menu My folders
Go to page: First ... 54 55 56 57 [58] 59 60 61 62 ... Last
[#] Wed Apr 28 2010 11:06:54 EDT from IGnatius T Foobar @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Perhaps the real problem is that you're still developing web sites that use frames. That went out of fashion a decade ago. Is there a particular reason for this design decision?

[#] Wed Apr 28 2010 11:57:24 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Generics, first class functions, and operator overloading in Scala. Starting to look like C++ here. (I don't know if this is the best way to write
this, and I haven't checked whether the inlining is actually working for this particular usage, but it demonstrates the principle.)

import Numeric._

class TraversableWrapper[T](val wrapped : Traversable[T]) {
@inline final def vectorize[T]
(binaryOp : (T, T) => T)
(seq : Traversable[T], scalar : T) : Traversable[T] = : T) => binaryOp(x, scalar))

@inline final def +(scalar : T)(implicit numeric: Numeric[T]) =
vectorize(, scalar)

object Lists extends Application {
@inline final implicit def ops[T](seq : Traversable[T]) : TraversableWrapper[T] =
new TraversableWrapper[T](seq)

val list = List(1, 2)
println(list) // Prints "List(1, 2)"
println(list + 1) // Prints "List(2, 3)"

[#] Wed Apr 28 2010 15:06:32 EDT from Spell Binder @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

LS: Re: Monads.

I don't grasp the category theory of monads, either. From what I can gather from reading about Haskell, a monad is a way to model a specific kind of sequential behavior but still be able to integrate into a functional paradigm. This is probably more important in Haskell than other languages since Haskell code is evaluated lazily; i.e. code is only executed when the result of an expression is needed. Monads provide the tools to implement strict evaluation of code, but they can also be used to model other kinds of behavior.

As far as the Option type in Scala. If it acts like Haskell's Maybe type, then the real benefit is not that it acts like a container that can only hold one value, but that it's a container that can hold either one value or no value at all. The explanation I've read about Maybe compares it to a database, where a field in a record could contain a value, or it could contain NIL. fold and map operations on a single Option probably aren't very useful. However, folding over a list of Option would be more interesting. One way to implement a fold over a list of Option would return "Nothing" if any sub-fold over the list returned "Nothing".
Maybe Binder

[#] Wed Apr 28 2010 16:15:42 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

... except that that doesn't appear to be what fold/reduce et al actually /do/ in Scala...

def reduce[U >: T](op: (U, U) => U): U = {
var r: U = next
while (hasNext) r = op(r, next)

[above is the leaf node code from the upcoming parallel collections framework.'

[#] Wed Apr 28 2010 18:37:42 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Perhaps the real problem is that you're still developing web sites that

use frames. That went out of fashion a decade ago. Is there a
particular reason for this design decision?

You're about the 8th person to ask that, and the reason is this. Apparently there's only one other guy in the world who has the same problem as me...

But before I explain, just because it's out of fashion doesn't mean it's bad.
Our design girl goes on and on how designing by tables is out of fashion but being so old, all the browsers finally do it consistently and well and quick.
Now the new paradigm is css and it all sucks and is broken and confusing and doesn't work the same across browsers so you STILL have to code for each browser.
How is this better? It's in fashion? Gar. Progress.

Anyway, the problem is that the menu runs a bunch of applications in the lower frame. These applications are C CGIs perl scripts java servlets, all sorts of things, some of them I think are even shell scripts.
Some use templates, some have html hard coded into them.
There's no way to go through every single program (there are at least 50-60 of them) and fix them so that they can render this menu at the top.
So I'm using a frame.

[#] Thu Apr 29 2010 10:00:33 EDT from Spell Binder @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Apr 28 2010 4:15pm from LoanShark @uncnsrd

... except that that doesn't appear to be what fold/reduce et al
actually /do/ in Scala...

def reduce[U >: T](op: (U, U) => U): U = {
var r: U = next
while (hasNext) r = op(r, next)

If I had to take a stab at this, my guess would be that reduce() itself is written generically to handle any type, so the decision about how to compute would be handled by op.

Bear with me as I've never written Scala:

def OptionMult(current: Int, next: Int): Option[Int] = {
if (current < 0 || next < 0) then return Nothing
current * next

This is a contrived example, but makes the point. It's up to the reduction function that gets passed into reduce() to decide what to do. For the Option type, you can have it return "Nothing" for whatever reason you like.

[#] Thu Apr 29 2010 11:49:32 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

correct Scala would be:

def OptionMult(current: Int, next: Int): Option[Int] = {
if (current < 0 || next < 0) then None
else Some(current * next)

In Scala, everything is an expression, and expressions can be block-structured with curly braces. There is no "return" but there probably is a way to approximate "return" with a library-defined control structure. Something similar has been done for "break."

What I've just typed above defines a Scala function that will compile and run. But you can't pass it to Scala's reduce() because the type signature doesn't match (U, U) => U. Instead, the type signature matches (U, U) => Option[U].

If you had a fast parallel mapreduce[B] method (which computes map and reduce in a single step) with this signature:

mapreduce[B](map: A => B, reduce: (B, B) => B) : B

Then you could pass it a map method defined like this:

def map(x: Int) : Option[Int] =
if (x < 0) then None else Some(x)

**This could give you the desired semantics, but not the desired optimization of early termination, because of the way reduce() itself is written!**

[#] Thu Apr 29 2010 16:50:54 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

*giggle snicker giggle*

Dean Wampler, Ph.D., the co-author of O'Reilly's "Programming Scala", offered this comment on the sudden industry switch to Scala vs. the less
appealing alternatives:

We all know that object-oriented programming is dead and buried. Scala gives you a 'grace period'; you can use its deprecated support for objects
until you've ported your code to use Monads.

[#] Thu Apr 29 2010 17:28:43 EDT from Spell Binder @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Even in Haskell, if you write some code in the Maybe monad and one of the computations returns Nothing, the rest of the chain still gets computed, but the rest of the steps should all just pass the Nothing along without doing anything else. Thus, you don't actually abort the chain, but once one element returns Nothing, the rest of the chain should compute with very little overhead.
Nothing Binder

[#] Fri Apr 30 2010 11:41:55 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

So Maybe the Maybe monad isn't the right tool for the job, nor mapreduce().

mapreduce() itself suffers problems when the binary operator you invoke it over is very lightweight, for example, just summing a list of integers; in that particular case, on the JVM, you take a factor of two performance hit relative to a handwritten while loop over an Array, and that's regardless of whether the implementation language is Java or Scala. When 'op' is heavier, the function call overhead vanishes into the noise, however.

But this all suggests that mapreduce() as it's defined in most parallel execution frameworks is defined around the wrong set of primitives. The primitive operation should be:

def fastmapreduce[B](leafMapReduce: (Array[A], Range) => B, reduce: (B, B) => B)

Which allows two additional optimizations: (1) hand-inlining of the map/reduce functions within the user-provided leafMapReduce; (2) leafMapReduce could be defined as above with early termination optimizations, or any other optimization that is dependent on knowledge of the aggregate data structure...

It then becomes trivial to define mapreduce[B] as a convenience wrapper around fastmapreduce[B] with the usual semantics

[#] Sat May 01 2010 22:26:54 EDT from Spell Binder @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

I'm with ya on that, LS. That's one reason why, even though I'm very interested in functional programming, I don't think it's the be-all end-all solution to programming. Don't get me wrong, I can definitely appreciate the succinct code of languages like Haskell, but I think the lengths that you have to go to to solve some practical problems and still maintain functional purity seem a little unecessary to me.

[#] Sun May 02 2010 20:24:35 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Yeah, on the other hand, I'm already using a lot of fake-closures in Java (aka anonymous inner classes) so it just makes sense to have a rreal-closures. Too bad Oracle is dropping the ball on that.

[#] Tue May 04 2010 11:31:52 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

One more reason why C# rocks Java's socks off (I'm so close to switching teams it's not funny)

[#] Tue May 04 2010 11:33:30 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

And some summary:

LINQ is implemented in terms of lambdas, and the compiler can transparently represent lambdas as ASTs if a library requests it. Functional programming gone mainstream.

[#] Wed May 05 2010 12:51:35 EDT from Peter Pulse @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

My apt-mate keeps going on about C#, he was a linux weenie for years but he has gone to the dark side. But ya it does sound good, I need to learn it some time.

[#] Wed May 05 2010 16:38:48 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

LINQ is nice but not as sweet as I at first hoped (the problem is that your repository returns IQueryable<T> but your entity model's association collections only seem to implement IEnumerable<T>.. from what I can tell from Googling... which gives you none of the SQL passthrough on the map/filter/fold operators that you get for queries that were executed through the normal context.

However, the concepts of LINQ are interesting and I may end up reusing a lot of its structure in a web service architecture I've been considering building at work - the idea of LINQ is that the compiler reifies native language syntax as Expression objects that are made available to query providers... the query providers parse the Expression objects (which are an AST for C#, basically), but since it's mostly simple lambda expressions, which are declarative, it's translatable to SQL) and generate SQL.
The idea is to serialize these Expression objects via SOAP. Which means I expose a highly general API to my clients, and I don't have to anticipate all their needs... but I can still impose some limitations on what they're allowed to do.

[#] Sat May 08 2010 11:00:21 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Back to the Maybe/Option debate. In my aimless meanderings through the nether regions of the blogosphere, a few days ago I stumbled across a post by an obvious functional headcase. His take: "don't return null. Use a tail call."

In other words, every time you want to return null, use continuation-passing style instead. I think I can see the rationale behind that, and it might even be useful if applied carefully (reference the early termination optimization discussion above, for example.)

But on the other hand, seems taking functional to the extreme of terminal lunacy. (For example, I immediately looked for one example in my codebase where this would apply, and the first thing I stumbled upon was ALREADY a second-order function, so factoring that up to CPS would probably have made it way less comprehensible to the average programmer.)

Nonetheless, I wonder what a mapreduce() in CPS would look like

[#] Mon May 10 2010 21:34:22 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

It doesn't sound like koolaid is a big enough word for what you've been drinking.
I'm not saying that that stuff is bad, but it's just so many layers past what I'd ever consider doing (me and my neanderthal C speaking here)
I'm just trying to imagine what one of those linq operators actually compiles to.
I realize I'm one of those old antiquated codgers who's the 80's equivalent of the guy who never let go of cobol, but this stuff is really kinda scary on some level.
Rememer the lisp guys who figured that you had to do things their way to take a step towards real AI?
This seems like the same thing, though not the apparent goal.
I realize nothing large is ever going to get done in C or assembly, and you're going to need gargantuan constructs like this to make high minded things happen, and that's the way the world is going and that's fine, but coming from my stone age mentality it really is bizarre onsome level.

[#] Mon May 10 2010 23:00:05 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Ford: OK, let's suppose for the sake of argument that LINQ is totally the wrong way to go. But one still wants to build a web service that has an actual **query language** attached, rather than just a set of "get me this by such and such parameter" methods, and you have to write a new set of entry points every time one of your clients wants a slightly different query.

The problem is, this n-tier architecture problem domain **really sucks**, and especially when you're deploying the middle tier within a company with about 4000 employees, and the team responsible for building and servicing the back tier is just tiny compared to the rest of the org, and you're going to have to deal with all sorts of demands that those other 3999 (say) users could throw at you... well then you start to realize that writing a new method every time they ask for it, just isn't going to scale. And certainly nobody wants to just give these groups, who don't even work for my particular subsidiary of the Behemoth, direct SQL access

Throw into the mix that people are supposedly going to be accessing said backend tier from 12 time zones away and you have a real recipe for disaster on your hands unless you give them the option to optimize their bandwidth a bit, and safely.

I'm just trying to imagine what one of those linq operators actually compiles

Like I said, it compiles to a set of object invocations that construct an abstract syntax tree represntation of the query expression... *instead of* compiling to the actual object code for said query expression (which is also quite well-defined.) It's pretty simple once you get your head around the concept - which is rather easy if you've already been spending time learning about functional programming -- it's built around a mathematical formalism, *not* so much a particular query language per se (although it has one, of course.) And there are some simple examples out there in the documentation. But the devil is in the details of how to actually convert the damn thing to SQL or JPA-QL or whatever...

[#] Tue May 11 2010 04:36:08 EDT from LBRapid @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

any other fans of ruby and/or rails on here?

Go to page: First ... 54 55 56 57 [58] 59 60 61 62 ... Last