Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Haskell High Performance Programming

You're reading from   Haskell High Performance Programming Write Haskell programs that are robust and fast enough to stand up to the needs of today

Arrow left icon
Product type Paperback
Published in Sep 2016
Publisher Packt
ISBN-13 9781786464217
Length 408 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Samuli Thomasson Samuli Thomasson
Author Profile Icon Samuli Thomasson
Samuli Thomasson
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Identifying Bottlenecks 2. Choosing the Correct Data Structures FREE CHAPTER 3. Profile and Benchmark to Your Heart's Content 4. The Devil's in the Detail 5. Parallelize for Performance 6. I/O and Streaming 7. Concurrency and Performance 8. Tweaking the Compiler and Runtime System (GHC) 9. GHC Internals and Code Generation 10. Foreign Function Interface 11. Programming for the GPU with Accelerate 12. Scaling to the Cloud with Cloud Haskell 13. Functional Reactive Programming 14. Library Recommendations Index

Writing Accelerate programs

Accelerate arrays are indexed by similar data types with Repa arrays, in other words, snoc-style lists:

data Z
data tail :. head = tail :. head

Like Repa, type synonyms are provided for Accelerate indices:

type DIM0 = Z
type DIM1 = DIM0 :. Int
type DIM2 = DIM1 :. Int
...

The Accelerate array type is Array sh e. We can build accelerated arrays from lists with fromList:

> import Data.Array.Accelerate as A
> fromList (Z :. 5) [1..5]
Array (Z :. 5) [1,2,3,4,5]

Now let's try to do something with an Array: reverse it. Accelerate provides the function reverse, but it has this slightly daunting type signature:

reverse :: Elt e => Acc (Vector e) -> Acc (Vector e)

And if we try to apply reverse to an array directly, we are greeted with a type-mismatch error:

> A.reverse (fromList (Z :. 5) [1..] :: Array DIM1 Int)

<interactive>:24:12:
    Couldn't match expected type 'Acc (Vector e)'
                with actual type 'Array DIM1 Int...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime