Skip to main content

All Questions

1 vote
2 answers
109 views

I'm working out of Scala for the Impatient (3rd Edition). (I'm not doing this for a class.). I'm trying to implement a factorial function using to and reduceLeft without a loop or recursion. This ...
Christopher Spears's user avatar
1 vote
1 answer
172 views

I'm following this article on catamorphism and I'm trying to define a fold function for a recursive data type like this type Node anyType = Leaf Id (Maybe anyType) | Tree Id (List (Node ...
Dylanbob211's user avatar
  • 1,274
0 votes
4 answers
1k views

I want to write a function that takes a List [a_n; a_n-1; ...; a_0] with an accumulator acc. The function is supposed to calculate the sum of every element in the whole list raised to the i'th power. ...
linuxxx's user avatar
  • 37
11 votes
1 answer
405 views

Using the following catamorphism for natural numbers I can implement various arithmetic algorithms whithout having to deal with recursion: cataNat :: b -> (b -> b) -> Natural -> b cataNat ...
user avatar
0 votes
1 answer
232 views

The Y combinator (from the wikipedia article) is defined as: Y = \f.(\x.f(x x)) (\x.f(x x)) so when we call Y on g: Y g = (\f.(\x.f(x x)) (\x.f(x x))) g = (\x.g(x x)) (\x.g(x x)) = g((\x.g(x x)) ...
Mark Karavan's user avatar
  • 2,694
3 votes
2 answers
190 views

I have a variadic lifting function that allows for flat monadic chains without deeply nested function composition: const varArgs = f => { const go = args => Object.defineProperties( ...
user avatar
1 vote
4 answers
3k views

I'm trying to write a function that implements foldl in JavaScript. I'm trying to use recursion in the function but not being able to implement it. var foldl = function(f, acc, array) { if (...
Lucy's user avatar
  • 1,862
2 votes
1 answer
1k views

In A tutorial on universality and expressiveness of fold chapter 4.1, it states that this pattern of recursion h y [] = f y h y (x:xs) = g y x xs (h y xs) is primitive recursion, but I don't ...
Sid's user avatar
  • 85
6 votes
2 answers
4k views

I learning more and more about Erlang language and have recently faced some problem. I read about foldl(Fun, Acc0, List) -> Acc1 function. I used learnyousomeerlang.com tutorial and there was an ...
Marcin Majewski's user avatar
2 votes
3 answers
602 views

In this blog entry, "CSP and transducers in JavaScript", the author states: First, we have to realise that many array (or other collection) operations like map, filter and reverse can be defined in ...
hawkeye's user avatar
  • 36k
3 votes
3 answers
903 views

I have this simple function which returns a list of pairs with the adjacents elements of a list. adjacents :: [a] -> [(a,a)] adjacents (x:y:xs) = [(x,y)] ++ adjacents (y:xs) adjacents (x:xs) = [] ...
acrespo's user avatar
  • 1,144
48 votes
4 answers
11k views

In Haskell, like in many other functional languages, the function foldl is defined such that, for example, foldl (-) 0 [1,2,3,4] = -10. This is OK, because foldl (-) 0 [1, 2,3,4] is, by definition, ((...
Racket Noob's user avatar
  • 1,066
4 votes
2 answers
10k views

UPDATE - Solution Thanks to jacobm for his help, I came up with a solution. // Folding Recursion let reverse_list_3 theList = List.fold_left (fun element recursive_call -> recursive_call::...
Hristo's user avatar
  • 46.8k
177 votes
7 answers
50k views

Firstly, Real World Haskell, which I am reading, says to never use foldl and instead use foldl'. So I trust it. But I'm hazy on when to use foldr vs. foldl'. Though I can see the structure of how ...
J Cooper's user avatar
  • 17.1k