2.5. The GHCi Debugger. GHCi contains a simple imperative-style debugger in which you can stop a running computation in order to examine the values of variables. The debugger is integrated into GHCi, and is turned on by default: no flags are required to enable the debugging facilities. There is one major restriction: breakpoints and single-stepping are only available in interpreted modules; compiled code is invisible to the debugger[]. The debugger provides the following: The ability to set a breakpoint on a function definition or expression in the program. When the function is called, or the expression evaluated, GHCi suspends execution and returns to the prompt, where you can inspect the values of local variables before continuing with the execution.Execution can be single-stepped: the evaluator will suspend execution approximately after every reduction, allowing local variables to be inspected. 2.5.1.
Breakpoints and inspecting variables Let's use quicksort as a running example. Now, we run the program: ... Data.ByteString.Char8. O(n) The unfoldrN function is analogous to the List 'unfoldr'. unfoldrN builds a ByteString from a seed value. The function takes the element and returns Nothing if it is done producing the ByteString or returns Just (a,b), in which case, a is a prepending to the ByteString and b is used as the next element in a recursive call. To preven unfoldrN having O(n^2) complexity (as prepending a character to a ByteString is O(n), this unfoldr requires a maximum final size of the ByteString as an argument. cons can then be implemented in O(1) (i.e. a poke), and the unfoldr itself has linear complexity. The depth of the recursion is limited to this size, but may be less.
For lazy, infinite unfoldr, use unfoldr (from List). Examples: unfoldrN 10 (\x -> Just (x, chr (ord x + 1))) '0' == "0123456789" The following equation connects the depth-limited unfoldr to the List unfoldr: unfoldrN n == take n $ List.unfoldr. Hoogle. Hoogle is a Haskell API search engine, which allows you to search many standard Haskell libraries by either function name, or by approximate type signature. Example searches: map (a -> b) -> [a] -> [b] Ord a => [a] -> [a] Data.Map.insert Enter your own search at the top of the page. The Hoogle manual contains more details, including further details on search queries, how to install Hoogle as a command line application and how to integrate Hoogle with Firefox/Emacs/Vim etc. I am very interested in any feedback you may have. Please email me, or add an entry to my bug tracker. Math.Statistics. Modes :: Ord a => [a] -> [(Int, a)]Source Modes returns a sorted list of modes in descending order quantile :: (Fractional b, Ord b) => Double -> [b] -> bSource Sample variance Interquartile range Arbitrary quantile q of an unsorted list.
The quantile q of N |data points is the point whose (zero-based) index in the sorted |data set is closest to q(N-1). linreg :: Floating b => [(b, b)] -> (b, b, b)Source Least-squares linear regression of y against x for a |collection of (x, y) data, in the form of (b0, b1, r) |where the regression is y = b0 + b1 * x with Pearson |coefficient r devsq :: Floating a => [a] -> aSource Returns the sum of square deviations from their sample mean. Data.Map. An efficient implementation of maps from keys to values (dictionaries). Since many function names (but not the type name) clash with Prelude names, this module is usually imported qualified, e.g. import Data.Map (Map) import qualified Data.Map as Map The implementation of Map is based on size balanced binary trees (or trees of bounded balance) as described by: Stephen Adams, "Efficient sets: a balancing act", Journal of Functional Programming 3(4):553-562, October 1993, J.
Nievergelt and E.M. Note that the implementation is left-biased -- the elements of a first argument are always preferred to the second, for example in union or insert. Operation comments contain the operation time complexity in the Big-O notation. Data.Map. Note: You should use Data.Map.Strict instead of this module if: You will eventually need all the values stored.The stored values don't represent large virtual data structures to be lazily computed.
An efficient implementation of ordered maps from keys to values (dictionaries). These modules are intended to be imported qualified, to avoid name clashes with Prelude functions, e.g. import qualified Data.Map as Map The implementation of Map is based on size balanced binary trees (or trees of bounded balance) as described by: Stephen Adams, "Efficient sets: a balancing act", Journal of Functional Programming 3(4):553-562, October 1993, Note that the implementation is left-biased -- the elements of a first argument are always preferred to the second, for example in union or insert. Operation comments contain the operation time complexity in the Big-O notation ( Regular expressions. 1 Overview Chris Kuklewicz has developed a regular expression library for Haskell that has been implemented with a variety of backends.
Some of these backends are native Haskell implementations, others are not and rely on external C libraries such libpcre. New users may feel overwhelmed with the various options that are available to them. The following table provides an overview of the various features supported by each backend. There are also a number of alternate or complementary regular expression libs, including: Note: speed is something that should be benchmarked by the actual user, since the story changes so much with the task, new GHC, compiler flags, etc.
All support String, (Seq Char), ByteString, and (except for regex-posix) ByteString.Lazy. All are available from Hackage as tar.gz sources and from darcs. 1.1 regex-base This package exports Text.Regex.Base which re-exports Text.Regex.RegexLike and Text.Regex.Context. Which I hope to be fixed in ghc 6.6.1. Import Text.Regex.BACKEND. How to write a Haskell program. A developers' guide to creating a new Haskell project or program, and working in the Haskell developer ecosystem. Note: for learning the Haskell language itself we recommend these resources. 1 Recommended tools Almost all new Haskell projects use the following tools. Each is intrinsically useful, but using a set of common tools also helps everyone by increasing productivity, and you're more likely to get patches. 1.1 Revision control Use git or darcs unless you have a specific reason not to.
This page uses darcs in the examples. 1.2 Build system Built with Cabal Use Cabal. You should use cabal-install as a front-end for installing your Cabal library. Cabal-install is widely available, as part of the Haskell Platform, so you can probably assume your users will have it too. 1.3 Documentation For libraries, use Haddock. 1.4 Testing You can use QuickCheck or SmallCheck to test pure code. To get started, try Introduction to QuickCheck. 1.5 Distribution 1.6 Target Environment 2.1 Create a directory to: The Haskell Heap. The Haskell heap is a rather strange place. It’s not like the heap of a traditional, strictly evaluated language... ...which contains a lot of junk!
(Plain old data.) In the Haskell heap, every item is wrapped up nicely in a box: the Haskell heap is a heap of presents (thunks). When you actually want what’s inside the present, you open it up (evaluate it). Presents tend to have names, and sometimes when you open a present, you get a gift card (data constructor). Gift cards have two traits: they have a name (the Just gift card or the Right gift card), and they tell you where the rest of your presents are. But just as gift cards can lie around unused (that’s how the gift card companies make money!) Presents on the Haskell heap are rather mischievous. Understanding what happens when you open a present is key to understanding the time and space behavior of Haskell programs.
Next time: Evaluation on the Haskell Heap Technical notes.