CommonHaskellIdioms

There are a number of idioms, or code patterns, or styles of programming, that are frequently used by experienced programmers. In the same way for (i=0; i<10; i++) rolls off a C programmer's tongue, these idioms roll off the tongues (or keyboards) of the Haskell programmers. If you want them to roll off your tongue too, read these pages.

You may also want to see the FrequentlyAskedQuestions, or the more theoretical LessFrequentlyAskedQuestions.


This page really should be cleaned up a bit. Can someone think up some good categories for these?

Off the top of my head:

-- AndrewBromage?


Common Haskell Idioms or Design Patterns

PipeliningFunctions: Functions are frequently built up as a chain or `pipeline' of smaller functions, each taking input, processing it in some way, and passing it on to the next function in the chain.

TyingTheKnot: How to build a cyclic data structure.

TheZipper: Manipulate locations in a data structure.

(Chris Angus's list follows... please update the descriptions and fill in the pages, everyone! -- KeithWansbrough )

HigherOrderFunctions: abstraction.

CircularProgramming: see also TyingTheKnot.

InformationHiding: combinators ... Monads.

PipeliningFunctions.

StatePropagation: even backwards (see paper by JerzyKarczmarczuk? in Haskell'00 workship)

NonDeterminism.

IntermediateRepresentation: Pretty printer.

ExceptionMonad: can be viewed as null object in that we need not constantly check for failure.

StateMonad. hiding state to structure code.

IterationPattern. flatten to list and process.

FunctionalDispatch: pattern match and carry out work in separate functions.

MemoisingCafs: including: memoising functions by using CAF arrays.

DomainSpecificLanguages: domain-specific processing by means of a ``little language''. Also, if Haskell cannot do it then simulate this little language that can. (mini-interpreters).

PhantomTypes. (?)

SpecialistDataStructures: eg Using Split lists rather than lists. See also PurelyFunctionalDataStructures?.

NullObject: fail.

UnitObject: return just.

DecoratingStructures: transform one structure into another. Possibly use polymorphism to make structures the same but parameterised.

ConcreteTypeInstantiation: concrete type-instantiation [Debugging].

AbstractDataTypes: (?) monads.

ChainOfResponsibility: decouple pattern matching (arg1 then arg2 etc) see FunctionalDispatch.

WorkerWrapper: worker/wrapper pairing.

ErrorMonad: return Maybe x rather than x and error as we can unwrap Maybe a into a but not vice versa.

EfficiencyHints: (?) hints (strictify , dump state and continue)

IntermediateForm: create syntax tree rather than string; ChainOfResponsibility.

NonTrivialTypeSynonyms:

	e.g. newtype Miles = Miles Int rather than 
		type Miles = Int

PartialEvaluationToCaptureSeparationOfConcerns:

HigherOrderFunctionsToCaptureAConfigurableFramework


Add your own idioms below.

HashConsing: Saving memory by sharing structures.

FactoryFunction, SmartConstructor: Putting intelligence into your constructor functions.

FunctionsNotDataStructures, RunTimeCompilation: Turn your data structures into functions.

ContinuationPassingStyle: Abstracting your return values. Also MonadicContinuationPassingStyle.

NotJustMaybe: dont lock your functions with partial results into using Maybe

The paper DesignPatternsForFunctionalStrategicProgramming initiates a catalogue of design patterns for generic functional programming with StraFunski.


Return to FrontPage.

EditText of this page (last edited 2002/07/23)
FindPage by browsing or searching
SubscribeForChangeNotification via email for this page (or unsubscribe)