Here is a lisp procedure that simply adds 'a' to the absolute value of 'b':
(define (a-plus-abs-b a b)
((if (> b 0) + -) a b))
I think this is beautiful, and I am trying to find the best way of writing this in JavaScript. But my JavaScript code is not beautiful:
var plus = function(a,b) {
return a + b;
};
var minus = function(...
I am hoping to use Groovy more as a functional language than I can with Java, but one area that seems to be a problem is when I call to a stored procedure, as I am passing perhaps 40 parameters in a single call, but, I also need to do some prep work, at the moment before I even call.
So, for example, I need a time stamp, so I will have ...
I've been coding for a few years now, nothing too complicated. C++ is what i know best. I recently stumbled into Paul Graham's site, coding horror and now here.
What do i learn to 'enlighten myself with the ways' of functional programming?
...
On my journey to learning F#, I've run into a problem I cant solve. I have defined a custom type:
type BinTree =
| Node of int * BinTree * BinTree
| Empty
I have made a function which takes a tree, traverses it, and adds the elements it visits to a list, and returns it:
let rec inOrder tree =
seq{
match tree with
| Node (da...
I'm struggling to understand what precisely does it mean when a value has type A @cps[B,C] and what types of this form should I assign to my values when using the delimited continuations facility.
I've looked at some sources:
http://lamp.epfl.ch/~rompf/continuations-icfp09.pdf
http://www.scala-lang.org/node/2096
http://dcsobral.blogs...
I find functools.partial to be extremely useful, but I would like to be able to freeze arguments out of order (the argument you want to freeze is not always the first one) and I'd like to be able to apply it to several methods on a class at once, to make a proxy object that has the same methods as the underlying object except with some o...
I hope you can help me with these exercises I have been stuck with. I am not in particular looking for the answers. Tips that help me solve them myself are just as good :)
1. Write a function implode : char list -> string so that implode s
returns the characters concatenated into a string:
let implode (cArray:char list) = List.foldBack...
I was reading Joel On Software today and ran across this quote:
Without understanding functional
programming, you can't invent
MapReduce, the algorithm that makes
Google so massively scalable. The
terms Map and Reduce come from Lisp
and functional programming. MapReduce
is, in retrospect, obvious to anyone
who remembers...
More specifically, how do you model a functional program, or one developed using the Functional Style (without classes) using a diagram, and not textual representation, is it at all possible and could someone please direct me towards the nearest application that would do this (open source, of free as in beer, if you please)
...
I recently asked about functional programs having no side effects, and learned what this means for making parallelized tasks trivial. Specifically, that "pure" functions make this trivial as they have no side effects.
I've also recently been looking into LINQ and lambda expressions as I've run across examples many times here on StackOve...
The :: operator in F# always prepends elements to the list. Is there an operator that appends to the list? I'm guessing that using @ operator
[1; 2; 3] @ [4]
would be less efficient, than appending one element.
...
Persistent data structures depend on the sharing of structure for efficiency. For an example, see here.
How can I preserve the structure sharing when I serialize the data structures and write them to a file or database? If I just naively traverse the datastructures, I'll store the correct values, but I'll lose the structure sharing....
Hello.
I have written 2 implementation of bubble sort algorithm in C and Haskell.
Haskell implementation:
module Main where
main = do
contents <- readFile "./data"
print "Data loaded. Sorting.."
let newcontents = bubblesort contents
writeFile "./data_new_ghc" newcontents
print "Sorting done"
bubblesort list = sort li...
In Haskell, lifted type products mean that there's a semantic difference between (a,b,c) and (a, (b, c)).
If all pattern matches of all products was always irrefutable, then there would be no difference, and (a, b, c) could be syntactic sugar for (a, (b, c)).
Why did Haskell choose to lift type products?
...
Could anyone give some pointers on why the unpure computations in Haskell are modeled as monads?
I mean monad is just an interface with 4 operations, so what was the reasoning to modeling side-effects in it?
...
Hello Guys,
I was wondering if i extract the common where clause query into a common expression would it make my query much faster, if i have say something like 10 linq queries on a collection with exact same 1st part of the where clause.
I have done a small example to explain a bit more .
public class Person
{
public string Fir...
Closures are poor man's objects and vice versa.
I have seen this statement at many places on the web (including SO) but I don't quite understand what it means. Could someone please explain what it exactly means?
If possible, please include examples in your answer.
Thanks.
...
I'm reading about functional programming (in academic purpose) and I've noticed that Pattern Matching is mentioned in many articles as one of the core features of functional languages.
Can someone explain for a Java/C++/JavaScript developer what does it mean?
...
In the context of functional programming which is the correct term to use: persistent or immutable? When I Google "immutable data structures" I get a Wikipedia link to an article on "Persistent data structure" which even goes on to say:
such data structures are effectively
immutable
Which further confuses things for me. Do functi...
I read through the javadoc and couldn't find anything that resembles it.
...