archives

Optimal map API

This has just crossed my mind:

Functional APIs and imperative ones often differ in the way that functional ones make use of function-passing as a way to manipulate data. For example, in Haskell, there's filter:

 filter :: (a -> Bool) -> [a] -> [a] 

Used like this:

 filter somecondition oldlist 

For lists, this can be simulated in say, Java by using:

ListIterator<E> it = list.listIterator();
while(it.hasNext()) {
  if(!somecondition(it.next())) {
    it.remove();
  }
}

While it is possible to implement this and other operations on lists equally fast, it doesn't seem to be the case for maps. Consider the following task:
You have a map from strings to int. You get a string "str" and an int "n". If the value at the position "str" is smaller than "n", you delete it, otherwise you overwrite it with "n" plus the old value(if there was no entry, the old one is assumed 0). In Haskell I would implement this using alter:

 alter :: (Maybe a -> Maybe a) -> k -> Map k a -> Map k a 

In this case:

alter (\x -> case x of
             Just v  -> if v < n
                        then Nothing
                        else Just (v+n)
             Nothing -> Just n) str oldmap 

This traverses the tree exactly once, while my Java implementation

Integer value = map.get(str);
if(value==null) {
  map.put(str,n);
}
else {
  if(value<n) {
    map.remove(str);
  }
  else {
    map.put(str,n+value);
  }
}

traverses the map twice(once for retrieval, once for insertion/deletion).
Is this (or equivalent performance issues) relevant for API design? Can every such problem be solved using iterators?

Lambda expressions in VB.NET

I thought folks might be interested to see that lambda expressions are coming to Visual Basic .NET.

http://www.panopticoncentral.net/archive/2006/12/08/18587.aspx

There's an interesting discussion going on concerning the proposed syntax.

excitement in language research?

I'm starting grad school in computer science next year and I'm hoping to focus on languages. Needless to say, LtU is a daily favorite. The contributors here have introduced me to many interesting papers and discussions.

I'm curious to hear from people who are working in the field, going to conferences, etc... What are some active areas in language research today? What do you think are the most exciting recent developments?

What about visual programming? Multi-paradigm programming (or programming 'paradigms' period)? Compiler design and optimization? Language support for concurrency? Formalisms for computation, translation, type-systems...

I hope this isn't too intense. Thanks in advance.