functional-programming

Modifying multiple Lists inside a function and returning it in Scala

I have a List of type [T] and [B] in scala, with an object e of type E. I want to make a function that accepts those three parameters: def doSomething(t : List[T], b List[B], e : E) { ... } However I realise that List is immutable, and anything passed to a function is considered as val (not var). But I need to modify t and b and ret...

Why to use LISP today, when there are Scala, Erlang, Haskell etc...

In the past LISP was the only powerful functional programming language, as far as I understand. Now there are lots, why do people still use LISP with its weird syntax? Is there a unique killer-feature of a kind? ...

Difference between a procedure and a combinator?

I've been using Scheme and Common Lisp for a while and there is one thing about nomenclature that I never got: I know that combinators are procedures with no free variables, but I seldom see them being called "combinators", except for those that deal with lists and other sequences. Is my perception correct? Or is there some other defini...

Why sum x y is of type (Num a) => a -> a -> a in Haskell?

I've been reading about Haskell and I'm having a hard time understanding how function definitions are handled in this language. Let's say I'm defining a sum function: let sum x y = x + y if I query Haskell for its type :t sum I get sum :: (Num a) => a -> a -> a What does it mean the => operator? Does it have anything to do wit...

Some issues when using WinGHCi

With WinGHCi, how can one implement the following code? soma :: Int -> Int soma 1 = aluno 1 soma n = aluno n + soma (n-1) I am currently writing multiline code using :{ ... :} but that doesn't seem to solve the issue, in this case. Also, why doesn't something as soma x y = x + y work, when I'm working in WinGHCi? I can only do i...

Implicit currying in Scheme with syntax-rules?

Jeffrey Meunier has an implicit Curry macro here, which uses defmacro. I was wondering if someone has ever written this with syntax-rules? ...

What are "n+k patterns" and why are they banned from Haskell 2010 ?

When reading Wikipedia's entry on Haskell 2010 I stumbled across this: -- using only prefix notation and n+k-patterns (no longer allowed in Haskell 2010) factorial 0 = 1 factorial (n+1) = (*) (n+1) (factorial n) What do they mean by "n+k patterns"? I guess its the second line, but I don't get what might be wrong with it. Could any one...

How much time have you invested in order to have a good grasp on Haskell ?

I know this question may sound silly, but I am learning (at least trying) Haskell for about 4 days. I've already finished to read http://learnyouahaskell.com/, and now I am investing time in: The Haskell Road to Logic, Math and Programming, and things got really complicated for me. I don't have experience in functional programming, just ...

Is there a way to tell if I'm using recursion in Python?

I'm writing a function to traverse the user's file system and create a tree representing that directory (the tree is really a TreeView widget in Tkinter, but that's functionally a tree). The best way I can think of doing this is recursion. However, one of my cases in the function requires me to know if it is the "original" function call...

Why does <$> act only on the second member of a pair?

Take a quick peek at the following interactive session in GHCi: Prelude> import Control.Applicative Prelude Control.Applicative> (+1) <$> [1,2] [2,3] Prelude Control.Applicative> (+1) <$> (1,2) (1,3) I guess there is a good reason for the behavior of <$> regarding pairs, but I wasn't able to find one so far, so: why is <$> (or `fma...

Some languages and uses for monads

Hi guys, According to you, which language do you think would be the best for implementing monads (Python/Ruby/LISP)?,also can anyone tell me some possible uses of monads (please give examples),like exceptions? Thanks in advance ...

Is there a relationship between calling a function and instantiating an object in pure functional languages?

Imagine a simple (made up) language where functions look like: function f(a, b) = c + 42 where c = a * b (Say it's a subset of Lisp that includes 'defun' and 'let'.) Also imagine that it includes immutable objects that look like: struct s(a, b, c = a * b) Again analogizing to Lisp (this time a superset), say a struct definitio...

Decomposition (modularity) in functional languages

Got an idea: functions (in FP) could be composed similar was as components in OOP. For components in OOP we use interfaces. For functions we could use delegates. Goal is to achieve decomposition, modularity and interchangeability. We could employ dependency injection to make it easier. I tried to find something about the topic. No luck....

What do we call this (new?) higher-order function?

I am trying to name what I think is a new idea for a higher-order function. To the important part, here is the code in Python and Haskell to demonstrate the concept, which will be explained afterward. Python: >>> def pleat(f, l): return map(lambda t: f(*t), zip(l, l[1:])) >>> pleat(operator.add, [0, 1, 2, 3]) [1, 3, 5] Haskell...

Will I develop good/bad habits because of lazy evaluation?

Hi all, I'm looking to learn functional programming with either Haskell or F#. Are there any programming habits (good or bad) that could form as a result Haskell's lazy evaluation? I like the idea of Haskell's functional programming purity for the purposes of understanding functional programming. I'm just a bit worried about two things...

Recursively (?) compose LINQ predicates into a single predicate.

(EDIT: I have asked the wrong question. The real problem I'm having is over at http://stackoverflow.com/questions/3782940/compose-linq-to-sql-predicates-into-a-single-predicate - but this one got some good answers so I've left it up!) Given the following search text: "keyword1 keyword2 keyword3 ... keywordN" I want to end up with t...

Compose LINQ-to-SQL predicates into a single predicate.

(An earlier question, http://stackoverflow.com/questions/3782799/recursively-compose-linq-predicates-into-a-single-predicate, is similar to this but I actually asked the wrong question... the solution there satisfied the question as posed, but isn't actually what I need. They are different, though. Honest.) Given the following search te...

Combine function in SML

Hey, im very new to SML and programming alltogether, i want to write a function that combine within lists, such that [x1,x2,x3,x4,...] = [(x1,x2),(x3,x4),...] Any hints or help for me to go in the right direction is highly appreciated. ...

Python comparison functions

I have some data that lends itself to representation as a value and a comparison function, (val, f), so another value can be checked against it by seeing if f(val, another) is True. That's easy. Some of them just need >, <, or == as f, however, and I can't find a clean way of using them; I end up writing things like ScorePoint(60, la...

How to make this code more compact and idiomatic?

Hullo all. I am a C# programmer, exploring F# in my free time. I have written the following little program for image convolution in 2D. open System let convolve y x = y |> List.map (fun ye -> x |> List.map ((*) ye)) |> List.mapi (fun i l -> [for q in 1..i -> 0] @ l @ [for q in 1..(l.Length - i - 1) -> 0]) |> List.reduce (fu...