Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

After reading @ray vernagus post about using ArcObjects with F#, I have been wondering ... what types of GIS problems are better handled by Functional Programming, as opposed to more traditional forms of programming?

Perhaps more specifically, when would I be better off using F# as opposed to C# with ArcObjects?

share|improve this question
    
Perhaps the paradigm one chooses depends upon what one intends to program for, one of your links contains references to alternate paradigms and a comparison of what they are suited for en.wikipedia.org/wiki/Comparison_of_programming_paradigms –  Dan Patterson Apr 21 '12 at 20:14
    
@DanPatterson Thanks for the feedback. What I'd like to see are specific GIS problems where F# is more suitable than C#. If I can see that, then I might be able to justify investing time to learn it. I've got a sneaking suspicion that things like map algebra and network flow solvers are good candidates, but just haven't seen any case studies. –  Kirk Kuykendall Apr 23 '12 at 22:21
1  
"Map algebra" (from the 1980's) is functional programming. –  whuber May 11 '13 at 14:56
    
@whuber As I understand functional programming, it allows what we would normally think of as formulae, to be treated as data. Spreadsheets, for example, do this. I don't see a way to assign a function to a raster cell. It seems like this could be used to more rationally create something like a zoning map. Each zoning category could have a different suitability function. With units like property tax revenue. The inputs might include surrounding zoning. Zoning a parcel as residential might not yield as much tax revenue when it's near property zoned industrial. –  Kirk Kuykendall May 13 '13 at 14:39
    
I believe you are thinking of something different, more akin to "computing on functions." According to [Wikipedia], functional programming is "a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data." Map algebra, almost all of which consists of pure functions, is a straightforward (but limited) example of this. The alternative of, say, looping over cells in Python is the opposite of functional programming. Strong FP paradigms exist now in R and Mathematica, which provide many GIS-related examples. –  whuber May 13 '13 at 14:45
add comment

3 Answers

The single biggest reason why functional programming has come back into vogue lately is concurrency. Being able to do processing in parallel for performance reasons is becoming massively important in computing overall and GIS is no exception. Functional programming has some serious benefits in the context of creating parallel systems because of how much it emphasizes immutability and recursion. Because of these properties most functional languages tend to simply sidestep issues like locking that make parallel programming in imperative languages a massive headache.

That being said, I think the GIS field has a long way to go before you will really be able to take advantage of a lot of what functional programming has to offer. Existing technologies and libraries are simply too fixated on Object Orientation and a generally imperative approach. Sadly, just because you can use ArcObjects from F# doesn't necessarily mean the underlying libraries will actually play nice with a functional style of programming.

share|improve this answer
add comment

Not strictly programming, but ArcToolbox follows a more functional design paradigm.

  • Most tools are designed to accept a set of inputs, run a function, and return the outputs without the influence of external state.
  • Most tools do not edit existing layers, but create new ones (immutability).
  • Many tools are similar in operation to a map function. They operate on sets of objects (feature set) rather than use iteration to process lower level objects (geometry).
  • Basic tools such as union, intersect, and dissolve can solve numerous problems that would be difficult to express in a declarative language such as SQL.

The functional approach of ArcToolbox lets us do spatial analysis without needing to write code. The user can work with a simple set of elements such as layers, and not worry about iteration, maintaining state, or complicated side effects.

share|improve this answer
add comment

I am new to functional programming myself so these are just a few thoughts.

There's an interesting example of a Ray Tracer in F# that illustrates some of the strengths of functional programming, namely higher-order functions, recursion, parallelism, and pattern matching. Extending some of those concepts it would seem that raster math is one key area in GIS that functional programming might be particularly suited for.

enter image description here

edit: Here's another example from the same site: Rule 30 Cellular Automata

Another thought is that you don't have to write your entire program in F#. You can have the main program written in C# and create projects/assemblies in F# that solve specific functional programming problems. I've read you can also use ILMerge to merge C# and F# into one executable/assembly.

Lastly, there are a lot of functional programming things you can do in C# with LINQ, through its use of lambda expressions, higher order functions (Select, Where, etc), sequence pattern matching, etc.

share|improve this answer
    
Thanks for the link to the ray tracer. Took liberty of adding image to your answer. –  Kirk Kuykendall May 12 '13 at 15:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.