functional-programming

How does functional programming apply to simulations?

How do functional programmers and functional languages approach the domain of simulations, which seem to be most naturally handled by object-oriented languages? Are there open-source examples of complex simulations written in a (mostly) functional style? What changes of perspective would an OO-programmer need, in order to approach simu...

Zipper like data structure with more then one cursor

The Zipper data structure is great when one wants to traverse a tree and keep the current position, but what data structure one should use if they want to track more then one position? Let me explain with examples: Someone on the #haskell channel has told me that zippers are used in yi editor to represent the cursor position. This is...

Performance implications of using Functional style Javascript vs "procedural"

Has anybody done benchmarking, or can link to an article on this subject? Particularly interested in IE results, since usually JS performance is not a problem in other browsers. I would like to know how much slower it is to do something like: var numbers = [1, 2, 3, 4, 5, 6, 7]; var results = numbers.map(function() { // do some stuf...

How do I get (a, b) => c from a => b => c in Scala?

If I have: val f : A => B => C This is shorthand for: val f : Function1[A, Function1[B, C]] How do I get a function g with the signature: val g : (A, B) => C = error("todo") (i.e.) val g : Function2[A, B, C] //or possibly val g : Function1[(A, B), C] in terms of f? ...

Why is currying and uncurrying not implicit in scala

If I have a function: f : A => B => C I can define an implicit conversion such that this can be used where a function (A, B) => C is expected. This goes in the other direction also. Why are these conversions not implicit (or available implicitly)? I am assuming that bad things could happen for some value of bad things. What value is ...

Appending a label to immutable case classes in Scala

Im trying to create a parser for a small language with commands including labels and goto: ... lazy val cmds = opt("{")~>rep(cmd<~opt(";"))<~opt("}") ^^ {...} lazy val cmd = ("if"~boolexpr~"then"~cmds~"else"~cmds ^^ { case _~b~_~c1~_~c2 => IFCMD(boolexpr,c1 | ident ~":="~numericLit ^^ {case i1~_~v => ASSIGN(i1,v) } | "goto" ~>ide...

Combine memoization and tail-recursion

Is it possible to combine memoization and tail-recursion somehow? I'm learning F# at the moment and understand both concepts but can't seem to combine them. Suppose I have the following memoize function (from Real-World Functional Programming): let memoize f = let cache = new Dictionary<_, _>() (fun x -> match cache.Try...

why java number one ?

Why is Java the most used programming language ? Why are the most programmers jobs for Java ? Don't get me wrong here ? I like Java and I work in Java ? I don't have anything against it ? Also, I'm trying to learn some other stuff out of the OOP box, like Clojure with its functional programming. But, I'm wondering, why is Java number...

Connecting to Oracle from F#

How would I go about connecting to oracle from F#? Is there a drive or can I load up the C# driver? I'm very new to F#. ...

infinite loop in functional programming ?

I was wondering: can infinite loops be done in functional programming? example: when using the windows API to get windows messages, it is usually implemented in a loop. I know it is possible to make a function that will keep going into recursion indefinitely. I expect that this will result in a stack overflow. are infinite loop the...

What are the practical limitations of a non-turing complete language like Coq?

As there are non-Turing complete languages out there, and given I didn't study Comp Sci at university, could someone explain something that a Turing-incomplete language (like Coq) cannot do? Or is the completeness/incompleteness of no real practical interest (i.e. does it not make much difference in practice)? EDIT - I'm looking for an...

What is the correct term for the following functional programming pattern?

I've heard it referred to as a stream, as an infinite list, and sometimes even as a lazy sequence. What is the correct term for the following pattern? (Clojure code shown) (def first$ first) (defn second$ [str] (cond (empty? str) () true ((first (rest str))))) (defn stream-builder [next_ n] (cons n (cons (fn [] (stream-bu...

How to apply clojure?

I am learning Clojure and I really am loving some of its features. The time is coming to think of some real "pet projects" and I realize I'm not sure how to actually use Clojure. I see many web and templating frameworks (e.g. Compojure), but somehow I'm in doubt on whether it's worth it. I feel that in the long run it can't serve the ne...

Looking for generic way to implement function in base class

I'm trying to do a simple implementation of the Specification pattern in my domain layer. If I have a static class full of specifications like this: public static class FooSpecifications { public static Func<Foo, bool> IsSuperhuman { get { return foo => foo.CanShootLasersOutOfItsEyes && foo.CanFly; } } } Then ...

Need Func to supply to Where() method of both IEnumerable and IQueryable.

I have a Func defined as follows: Func<Foo, bool> IsSuperhero = x => x.WearsUnderpantsOutsideTrousers; I can query IEnumerables like this: IEnumerable<Foo> foos = GetAllMyFoos(); var superFoos = foos.Where(IsSuperhero); But when I try to supply the same Func to the Where method of an IQueryable, I get: 'Cannot convert source type ...

Can I ignore thread safety when programming in Erlang?

I've just started learning about thread safety. This is making me code a lot more defensively, perhaps too defensively. Would using a functional language like Erlang completely rid me of this concern? ...

Is every method returning `this` a monad?

Is every method on a class which returs this a monad? ...

Weight-Biased Leftist Heaps: advantages of top-down version of merge?

I am self-studying Okasaki's Purely Functional Data Structures, now on exercise 3.4, which asks to reason about and implement a weight-biased leftist heap. This is my basic implementation: (* 3.4 (b) *) functor WeightBiasedLeftistHeap (Element : Ordered) : Heap = struct structure Elem = Element datatype Heap = E | T of int * Elem.T...

Why is smalltalk not a functional programming language?

With the renewed interest in functional programming languages, I've seen some similitudes between Smalltalk and FPL, namely closures ( BlockClosures in Smalltalk ) Yet, Smalltalk is not a FPL? What would be needed to consider it as such? ...

What could be the fastest and least painful way to learn LISP for a C developer?

I have been working as a C developer on Linux platform for sometime now. Recently finished K & R and did a little study of implementing OOP in C. Beside that I have studied C++ and Java. All of it has been on Linux platform. Now I plan to learn LISP. I have gone through LISP discussions directed towards beginners on SO, especially What’...