functional-programming

Graph based instead of stack based

I wonder about the idea of representing and executing programs using graphs. Some kind of stackless model where the each node in the graph represents a function and the edges represent arguments to the functions. In this way a function doesn't return the result to its caller,but passes the result as an arg to another function node. Total...

O(1) circular buffer in haskell?

I'm working on a small concept project in Haskell which requires a circular buffer. I've managed to create a buffer using arrays which has O(1) rotation, but of course requires O(N) for insertion/deletion. I've found an implementation using lists which appears to take O(1) for insertion and deletion, but since it maintains a left and rig...

How does TDD compare with Functional Programming Languages?

How does TDD compare with Functional Programming Languages like F# and Erlang? I haven't actually worked directly with a functional programming language yet, but from what I've seen of it, you have two sides of an equation and they have to balance like in algebra or accounting; this seems somewhat reminiscent of TDD where you define you...

What is Scala way of finding whether all the elements of an Array has same length?

I am new to Scala and but very old to Java and had some understanding working with FP languages like "Haskell". Here I am wondering how to implement this using Scala. There is a list of elements in an array all of them are strings and I just want to know if there is a way I can do this in Scala in a FP way. Here is my current version wh...

Are the implementation details of declarative languages inherently imperative

I'm reading 'Functional Programming' by Tomas Petricek & Jon Skeet and I understand the difference between declarative & imperative programming. What I was wondering is how are the primitive operators & functions implemented, are declarative languages constructed from imperative operators & functions. Cheers AWC ...

Haskell pattern matching - what is it?

What is pattern matching in Haskell and how is it related to guarded equations? I've tried looking for a simple explanation, but I haven't found one. EDIT: Someone tagged as homework. I don't go to school anymore, I'm just learning Haskell and I'm trying to understand this concept. Pure out of interest. ...

higher level functions in R - is there an official compose operator or curry function?

I can create a compose operator in R: `%c%` = function(x,y)function(...)x(y(...)) To be used like this: > numericNull = is.null %c% numeric > numericNull(myVec) [2] TRUE FALSE but I would like to know if there is an official set of functions to do this kind of thing and other operations such as currying in R. Largely this is ...

Scala equivalent to Haskell Monads

I had some experience in Haskell and currently learning Scala. Am wondering whether there is something equivalent to Monads in Scala?? ...

F# Code for Adventure Works Sample

hey everybody, it is very hard to find good samples for f# in the web. some samples show a simple web crawler for downloading stock data from yahoo or only code snippets of bigger ideas. i'm searching for an real world example outside the financial world. what about adventureworks? the current sample database is the base of many c# sam...

Tips & Traps in Learning XSLT and "Real" Functional Programming?

This is my first post. Please be gentle if in ignorance I violate accepted norms... I did spend significant time in the FAQs. ;-) Until recently my knowledge of XSLT was enough for my simple, straightforward needs. But a more advanced requirement sent me to reference material when "just trying stuff" didn't work. It was actually ...

Functional Programming - Implementing Scan (Prefix Sum) using Fold

Hi guys! I've been teaching myself functional programming, and I'm currently writing different higher order functions using folds. I'm stuck implementing scan (also known as prefix sum). My map implementation using fold looks like: (define (map op sequence) (fold-right (lambda (x l) (cons (op x) l)) nil sequence)) And my shot at sc...

How would be a functional approach to shifting certain array elements?

I have a Scala app with a list of items with checkboxes so the user select some, and click a button to shift them one position up (left). I decided to write a function to shift elements of some arbitrary type which meet a given predicate. So, if you have these elements: a b c D E f g h I and the predicate is "uppercase characters", th...

Iterate over list in haskell?

I'm writing an audio program in Haskell using Portaudio. I have a function that generates a list of samples I'd like to play, and I'm trying to play them using the following snippet inside main: curSamps <- return (chunk 1 (sineWave 440 44100)) forever $ do Right numSampsAvail <- getStreamWriteAvailable paStream Right NoError <- wri...

Is there a way to implement constraints in Haskell's type classes?

Is there some way (any way) to implement constraints in type classes? As an example of what I'm talking about, suppose I want to implement a Group as a type class. So a type would be a group if there are three functions: class Group a where product :: a -> a -> a inverse :: a -> a identity :: a But those are not any fu...

Is there an existing pattern to generate a list of the applications of a function to every combination of the items in two lists?

I'm just getting into functional programming and i'm in the "try out some non-trivial examples and ask others if I'm doing it wrong" phase. I'm following Don Syme's F# Tutorial and have decided to take a stab at the blackjack exercise at the end of Part II with a twist: he suggests treating Ace as 11 for simplicity's sake, but I decided ...

If Java people go to Scala, C# go to F#, where do Ruby people go for functional nirvana?

I know alot of Java people have started looking at Scala since it runs on the JVM, and alot of people in the Microsoft world are looking at F#, but what does Ruby have as a natural functional successor? In a pure FP sense Ruby doesn't lack anything, instead it has too much some may say. A functional language forces the programmer to not...

Does Scala have Guards?

Hi I started learning scala a few days back and when learning it, I am comparing it with other FP languages like (Haskell, Erlang) which I had some familiarity with. My Question is Does Scala has Guard sequences available, I went through pattern matching in Scala but is there any concept equivalent to Guards with otherwise and all? ...

Scala's Implementation of haskell last method

I am trying to do some examples programs in scala to get more familiar with the language, For that I am trying to re-implement some of the built in methods in Haskell, Most of these methods I am sure are also implemented in Scala too, But these are just for my practice. I think I can post some of code snippets (not all of them) to get a ...

homework on scheme

how to design a function content which inputs a single list of atoms lat and which returns the content of lat.Thus the content of '(a b c a b c d d) is '(a b c d). ...

dynamic programming pseudocode for Travelling Salesman

hi all. this is a dynamic programming pseudocode for TSP (Travelling Salesman Problem). i understood its optimal substructure but i can't figure out what the code in red brackets do. i am not asking anyone to write the actual code, i just need explanation on what is happening so i can write my own.... thanks:) here is a link for the ps...