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...
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?
...
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...
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...
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...
Jeffrey Meunier has an implicit Curry macro here, which uses defmacro. I was wondering if someone has ever written this with syntax-rules?
...
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...
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 ...
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...
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...
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
...
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...
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....
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...
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...
(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...
(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...
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.
...
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...
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...