Questions tagged [zipwith]
21 questions
6
votes
3 answers
Haskell zipWith
I want to sum a zipped list.
averageGrade :: [Float] -> [Int] -> Float
averageGrade [0.75 , 0.25] [6, 4] , result: 0,75*6 + 0.25*4 = 5.5
when I go to ghci and do the following:
sum(zipWith (*) [0.75, 0.25] [6, 4])
I get excactly what i want…

Sorun
- 143
- 5
5
votes
2 answers
How does the second parameter become a list of functions?
I am playing a bit with zipWith and encounter following:
Prelude Control.Applicative> :t zipWith id
zipWith id :: [b -> c] -> [b] -> [c]
Why does the compiler expect for the next argument a list of functions?
I tried to analyze, but could not…

softshipper
- 32,463
- 51
- 192
- 400
4
votes
2 answers
How do foldr and zipWith (:) work together?
I'm new to Haskell, and I've come across the following code that baffles me:
foldr (zipWith (:)) (repeat []) [[1,2,3],[4,5,6],[7,8,9,10]]
It produces the following result, which after playing around with it, I'm not entirely sure…

bug_spray
- 1,445
- 1
- 9
- 23
3
votes
0 answers
Slow stream fusion in Data.Vector.Storable.ZipWith but fast in Data.Vector.Unboxed.ZipWith
Currently, I found some strange behavior in my function. I have a transformation function that transforms from (x,a,b) -> (x,y,z). I'm using Data.Vector.Storable since I'm communicating with some external libs.
I estimated the time for the transfer…

blauerreimers
- 161
- 7
3
votes
3 answers
Can I use map function with 2 arrays?
I was wondering if any function exist that can do something like that
I already tried zipWith and some variations of the map, but no good results.
Only working solution to this is 2x ForEach, but I was wondering if I can minimalize this to one…

Łukasz Nizioł
- 45
- 5
3
votes
4 answers
Haskell, zip the element of a list with its length
The next lines should show how its has to work..
[14,2,344,41,5,666] after [(14,2),(2,1),(344,3),(5,1),(666,3)]
["Zoo","School","Net"] after [("Zoo",3),("School",6),("Net",3)]
Thats my code up to now
zipWithLength :: [a] -> [(a, Int)]
zipWithLength…

Janik Ti
- 75
- 4
3
votes
3 answers
Why does zipWith.zipWith work?
I am implementing a function combine :: [[a]] -> [[b]] -> (a -> b -> c) -> [[c]] which given two 2D lists, applies a given function f :: a -> b -> c to the entries of the 2D list. In other words:
[[a, b, c], [[r, s, t], [[f a…

Luke Collins
- 1,433
- 3
- 18
- 36
2
votes
1 answer
Couldn't match expected type 'MultTree b' with '[MultTree b]'
I'm relatively new to Haskell.
I'm trying to create a function zipWithMult :: (a -> b -> c) -> MultTree a -> MultTree b -> MultTree c that behaves similar to the function zipWith for lists. It should combine the two input trees using the given…

AndreasSt
- 183
- 1
- 7
2
votes
1 answer
How to define zipWith by using zip and list comprehension
I am trying to write zipWith function using zip and list comprehension. I need to zip the two lists after the function is applied. However I don't know where to use the list comprehension.
I tried doing two list comprehensions for each list.…

Kale Joe
- 163
- 6
1
vote
2 answers
Zipwith application in prolog
I have a hard time understanding this application of zipwith in Prolog and wondered if someone gets it. I already have an idea of what functor does, but I don't see how it applies in that case. I vaguely think that the two arg place arg no 1 and arg…

CoffeeRun
- 71
- 6
1
vote
2 answers
Elegant way in Haskell to output Fibonacci numbers using zipWith
I saw this implementation of the Fibonacci numbers in Haskell and I am still trying to figure out why this works properly. So apperently, the Fibonacci numbers can be written in a very compact way using the zipWith function. The implementation looks…

Jan Kreischer
- 679
- 3
- 8
- 21
1
vote
1 answer
How to use in Haskell zipWith correctly to create a [ [ int int ] ] list?
data Tegel = Teg Int Int
type RijTegels = [Tegel]
volleRijTegels :: RijTegels
volleRijTegels = ziptwee [21..36] (replicate 4 1 ++ replicate 4 2 ++ replicate 4 3 ++ replicate 4 4)
ziptwee :: [Int] -> [Int] -> RijTegels
ziptwee [] [] =…

Elzine Burger
- 25
- 4
1
vote
1 answer
How to combine following Observables into one in Kotlin?
I have these two Observables in Kotlin where is just act as a timer and another one is HTTP network call response Observer.
timerDisposable = Observable.timer(daleyABCControlResetSeconds, TimeUnit.SECONDS, AndroidSchedulers.mainThread())
…

Ahmed S. Durrani
- 1,535
- 2
- 17
- 41
0
votes
1 answer
What do I lose by setting up zipWithPadding like this? (alternate zipWith in Haskell)
This problem came up when I was trying to zip through lists of different length and I didn't want them to be cut by the shortest one. It was in a context where the list had integers that I wanted to add or multiply. My problem is how to set up the…

Marco_O
- 99
- 1
- 8
0
votes
1 answer
Haskell function to check differences between two lists
I want to write a function that checks if two lists are "almost" equal. The first parameter d is used for precision - the difference between the elements must not exceed d.
For example, nearlyEqual 0.5 [2,5] [2.5, 5.1] equals True, but nearlyEqual…

blair
- 21
- 4