Real World Haskell

Real World Haskell

Bryan O'Sullivan, John Goerzen, Don Stewart

Language: English

Pages: 714

ISBN: 0596514980

Format: PDF / Kindle (mobi) / ePub

Real World Haskell

Bryan O'Sullivan, John Goerzen, Don Stewart

Language: English

Pages: 714

ISBN: 0596514980

Format: PDF / Kindle (mobi) / ePub


This easy-to-use, fast-moving tutorial introduces you to functional programming with Haskell. You'll learn how to use Haskell in a variety of practical ways, from short scripts to large and demanding applications. Real World Haskell takes you through the basics of functional programming at a brisk pace, and then helps you increase your understanding of Haskell in real-world issues like I/O, performance, dealing with data, concurrency, and more as you move through each chapter. With this book, you will:

  • Understand the differences between procedural and functional programming
  • Learn the features of Haskell, and how to use it to develop useful programs
  • Interact with filesystems, databases, and network services
  • Write solid code with automated tests, code coverage, and error handling
  • Harness the power of multicore systems via concurrent and parallel programming

You'll find plenty of hands-on exercises, along with examples of real Haskell programs that you can modify, compile, and run. Whether or not you've used a functional language before, if you want to understand why Haskell is coming into its own as a practical language in so many major organizations, Real World Haskell is the best place to start.

Mastering Apache Spark

Programming Windows Identity Foundation

The Swift Programming Language

Swift High Performance

Swift for Beginners

Programming in Objective-C (4th Edition)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

programming languages, you’re likely to think of a variable as a way of identifying a memory location (or some equivalent) that can hold different values at different times. In an imperative language, we can change a variable’s value at any time, so that examining the memory location repeatedly can potentially give different results each time. The critical difference between these two notions of a variable is that in Haskell, once we’ve bound a variable to an expression, we know that we can

Constants Automating the Binding Passing String Data Between Haskell and C Typed Pointers Memory Management: Let the Garbage Collector Do the Work A High-Level Interface: Marshaling Data Marshaling ByteStrings Allocating Local C Data: The Storable Class Putting It All Together Matching on Strings Extracting Information About the Pattern Pattern Matching with Substrings The Real Deal: Compiling and Matching Regular Expressions 406 407 408 409 410 411 411 412 413 414 416 417 418 419 419 420 422

String customerName (Customer _ name _) = name customerAddress :: Customer -> [String] customerAddress (Customer _ _ address) = address For each of the fields that we name in our type definition, Haskell creates an accessor function of that name: ghci> :type customerID customerID :: Customer -> CustomerID We can still use the usual application syntax to create a value of this type: -- file: ch03/BookStore.hs customer1 = Customer 271828 "J.R. Hacker" ["255 Syntax Ct", "Milpitas, CA 95134",

printable ASCII characters are the only unescaped characters we emit. The more complicated escaping involves turning a character into the string "\u" followed by a four-character sequence of hexadecimal digits representing the numeric value of the Unicode character: -- file: ch05/PrettyJSON.hs smallHex :: Int -> Doc smallHex x = text "\\u" <> text (replicate (4 - length h) '0') <> text h where h = showHex x "" The showHex function comes from the Numeric library (you will need to import this at

and show can be used on quite large data structures without incident. The built-in read and show instances in Haskell are efficient and implemented in pure Haskell. For information on how to handle parsing exceptions, refer to Chapter 19. Let’s try it out in ghci: ghci> ghci> [Just ghci> let d1 = [Just 5, Nothing, Nothing, Just 8, Just 9]::[Maybe Int] putStrLn (show d1) 5,Nothing,Nothing,Just 8,Just 9] writeFile "test" (show d1) Important Built-in Typeclasses | 143 First, we assign d1 to be

Download sample

Download