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 Design Patterns

You're reading from   Haskell Design Patterns Take your Haskell and functional programming skills to the next level by exploring new idioms and design patterns

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher
ISBN-13 9781783988723
Length 166 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Ryan Lemmer Ryan Lemmer
Author Profile Icon Ryan Lemmer
Ryan Lemmer
Arrow right icon
View More author details
Toc

Patterns of generic programming

Jeremy Gibbons describes seven patterns of generic programming, where each pattern is viewed as a different kind of parameterization. For more information, refer to his article, Datatype-Generic Programming, which is available at http://www.cs.ox.ac.uk/jeremy.gibbons/publications/dgp.pdf.

Patterns 1 and 2 – functions

Functions parameterized by values are more general than functions with hardcoded values. This is the most simple kind of generic programming.

Functions parameterized by functions (higher order functions) represent a more powerful form of genericity.

Pattern 3 – polymorphic types and functions

Types parameterized by other types are as follows:

  Tree a = Leaf a | Node a (Tree a)
  – is more generic than
  TreeI  = Leaf Int | Node Int TreeI

Functions parameterized by polymorphic types are as follows:

  f :: Tree a → a
  – is more generic than
  g :: String → String

Pattern 4 – type-class polymorphism

In the...

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 £16.99/month. Cancel anytime