functional-programming

How hard is it to change from OOP thinking to pure FOP thinking in .net?

I have been working with c# for many years, since beta. I am having a bit of a time of it, moving from OOP to FOP. I started out with the concepts of procedural programming and functional composition in the late 80's and have been doing OO since around '95 when UML was in its infancy where I was programming in Delphi with the multi-parad...

Drawing a graph from a function

I have a complex mathematical C++ function. I want a translated and easy to read graph out of it. Is there any software which can analyze special mathematical functions and draw an easy to read graph? Assume it's an encryption algorithm code. I have tried a lot of software like Understand, WizGraph, etc. Is there something I should sea...

What would make you try (or not try) a new programming language?

I've been designing a pragmatic programming language for 5 or so years, and it probably won't be released for several more years (probably until after my current and next startups succeed or fail). In the mean time, I have two questions that may prove interesting: 1) What attributes of a new programming language could entice you try it...

Can you define an operator (***) in F#?

I'm working on Arrows in F# and I wanted to create a *** operator. I note, however, that (***), the necessary way to express an operator in a function definition, overlaps with the F# block comment syntax. So how could you actually express this? I thought of maybe .***. but I think that will actually treat the dots as part of the ope...

Is there a Haskell equivalent of OOP's abstract classes, using algebraic data types or polymorphism?

In Haskell, is it possible to write a function with a signature that can accept two different (although similar) data types, and operate differently depending on what type is passed in? An example might make my question clearer. If I have a function named myFunction, and two types named MyTypeA and MyTypeB, can I define myFunction so th...

How would I translate a Haskell type class into F#?

I'm trying to translate the Haskell core library's Arrows into F# (I think it's a good exercise to understanding Arrows and F# better, and I might be able to use them in a project I'm working on.) However, a direct translation isn't possible due to the difference in paradigms. Haskell uses type-classes to express this stuff, but I'm no...

Why does this Scala line return a Unit?

Here's a bit of Scala code to sum the values from 1 to 9 which are divisible by 3 or 5. Why does line 5 return a Unit and not a Boolean type? object Sample { def main(args : Array[String]) { val answer = (1 until 10).foldLeft(0) ((result, current) => { if ((current % 3 == 0) || (current % 5 == 0)) { ...

What's a good way to manage a lot of loosely related components in F#?

I'm trying to translate an idea I had from OOP concepts to FP concepts, but I'm not quite sure how to best go about it. I want to have multiple collections of records, but have individual records linked across the collections. In C# I would probably use multiple Dictionary objects with an Entity-specific ID as a common key, so that giv...

Is C# approching functional programing?

Many new features of C# remind me of functional programs such as LINQ. As this makes many operations easier it clutters the language. Is this approach for good or bad? ...

How to define parameter names for higher order functions in C#

In C# it is possible to create higher order functions, ie. functions g taking functions as arguments. Say I want to create such a function which given a function f and returns another function extending its functionality. How do I define argument names for the returned enhanced method? The motivation being, that I'm working with higher o...

Scheme List Derangement (Rearrangement of sorts)

im trying to write a function in Scheme where i accept a list and return all the different derangements (look below for definition) as a list of lists derangement: A list where no item is in the same place as the original list ex: '(a b c) -> '(cab) any help is appreciated! ...

Implementing functional programming in Perl

I am trying to learn pure functional programming language like Haskell as I am from Perl background and read that Perl can also implement functional programming techniques. So few qusetions came in mind: Whether it is worth doing it in Perl 5? Does Perl 6 will make a difference? Can anybody suggest some code/examples implementing functi...

Is the PartialFunction design inefficient?

This is something I've wondered about for a while. I see this pattern a lot: if (pf.isDefinedAt(in)) pf(in) By breaking this up into two separate calls, all of the patterns that were evaluated in #isDefinedAt are then also evaluated in #apply. For example: object Ex1 { def unapply(in: Int) : Option[String] = { println("Ex1") ...

What is the meaning of "callback.call( value, i, value )" in jQuery's each method?

each() method in jQuery contains such a statement: callback.call( value, i, value ) I couldn't understand what this statement means exactly. I know what callback and call mean but I couldn't get the arguments of the function call: (value,i,value). What does this mean? The statement is used in a for block of each() but my question...