DEFUN 2008 - Real World Haskell

Text-only Preview

Real World HaskellBryan O’[email protected]!A few things to expect about this tutorial:The pace will be rapidStop me and ask questions—early and oftenI assume no prior Haskell exposureA little bit about HaskellHaskell is a multi-paradigm language.It chooses some unusual, but principled, defaults:Pure functionsNon-strict evaluationImmutable dataStatic, strong typingWhy default to these behaviours?We want our code to be safe, modular, and tractable.Pure functionsDefinitionThe result of a pure function depends only on its visible inputs:Given identical inputs, it always computes the same result.It has no other observable effects.What are some consequences of this?Modularity leads to simplified reasoning about behaviour.Straightforward testing: no need for elaborate frameworks.Immutable dataDefinitionData is immutable (or purely functional) if it is never modifiedafter construction.To “modify” a value, we create a new value.Both new and old versions can coexist afterwards, so we getpersistent, versioned data for free.Modification is often easier than with mutable data.In multithreaded code, we do away with much elaboratelocking.Static, strong typingDefinitionA program is statically typed if we know the type of everyexpression before the program is run.DefinitionCode is strongly typed if the absence of certain classes of error canbe proven statically.Safety, modularity, and tractabilitySafety:As few nasty surprises at runtime as possible.Static typing and eased testing give us confidence.Modularity:We can build big pieces of code from smaller components.No need to focus on the details of the smaller parts.Tractability:All of this fits in our brain comfortably......leaving plenty of room for the application we care about.GHC, the Glorious Glasgow Haskell CompilerHave you got GHC yet?Download installer for Windows, OS X, or Linux here:http://www.haskell.org/ghc/download_ghc_683.htmlWhat’s special about GHC?Mature, portable, optimising compilerGreat tools:interactive shell and debuggertime and space profilerscode coverage analyserBSD-licensed, hence suitable for OSS and commercial useCounting linesThe classic Unix wc command counts the lines in some files:$ time wc -l *.fasta9975 1000-Rn_EST.fasta14032 chr18.fasta14005 chr19.fasta13980 chr20.fasta42017 chr_all.fasta94009 totalreal 0m0.017s