Questions tagged [stream-fusion]

8 questions
44
votes
1 answer

What is fusion in Haskell?

Every now and again I have been noticing the following in Haskell documentation: (for example in Data.Text): Subject to fusion What is fusion and how do I use it?
Abraham P
  • 15,029
  • 13
  • 58
  • 126
11
votes
0 answers

Why does -O2 have such a big impact on a simple L1 distance calculator in Haskell?

I have implemented a simple L1 distance calculator using Haskell. Since I am interested in performance I used unboxed vectors to store the images to compare. calculateL1Distance :: LabeledImage -> LabeledImage -> Int calculateL1Distance reference…
9
votes
2 answers

Why `Vector.length (Vector.replicate n 0)" is not fused?

The following code unexpectedly (at least for me) produces an intermediate vector: import qualified Data.Vector as Vector main :: IO () main = print (test n) n :: Int n = 1000000 test :: Int -> Int test n = Vector.length (Vector.replicate n (0…
Yuras
  • 13,856
  • 1
  • 45
  • 58
6
votes
1 answer

How to create Haskell containers that fuse?

I'm interested in creating a new Haskell container type (strict lists), and I want to make sure that operations on them are eligible for stream fusion. How do I opt-in to ghc's stream fusion capability? If my container is Traversable, will it fuse…
yong
  • 3,583
  • 16
  • 32
5
votes
1 answer

Ever increasing CPU consumption with Haskell and stream-fusion

Here is a short Haskell program that generates a 440 Hz sound. It uses pulseaudio as an audio backend. import GHC.Float import Control.Arrow import Sound.Pulse.Simple import qualified Data.List.Stream as S import Data.List type Time = Double type…
netom
  • 3,322
  • 2
  • 21
  • 21
1
vote
1 answer

How can I improve performance of this minmax implementation?

Here is my current code. It's a naive implementation. import System.Environment (getArgs) minmax [] = Nothing minmax [x] = Just (x, x) minmax (a:b:xs) = Just $ minmax' xs $ sort a b where minmax' [] lohi = lohi minmax' [x] lohi@(lo,…
user1685095
  • 5,787
  • 9
  • 51
  • 100
1
vote
1 answer

Cannot install Haskell package stream-fusion-0.1.2.5: Ambiguous occurence

I'm trying to build the project Barbarosa which requires the package stream-fusion-0.1.2.5. However cabal install fails with the following [3 of 3] Compiling Control.Monad.Stream ( Control/Monad/Stream.hs,…
xji
  • 7,341
  • 4
  • 40
  • 61
0
votes
1 answer

Which compilers today are capable of converting (map f (map g h)) into (map (f . g) h)?

Many techniques are used for this means, from as simple as Short Cut Fusion to elaborate Stream Fusion. I'm aware compilers such as GHC and MLTon rely considerably on this technique. Are there other compilers in existence that do so?