Hutton Book notes

© All Rights Reserved

7 views

Hutton Book notes

© All Rights Reserved

- CSP2151 Sample Test
- Rosario Training
- interfacing lcd in 4bit mode with lpc2138
- Number of Variables
- Assignment Part A
- A Concrete Approach to Learning How to Program
- UT Dallas Syllabus for cs1136.502 05f taught by George Steinhorst (csteinh)
- UT Dallas Syllabus for cs1136.003 05f taught by George Steinhorst (csteinh)
- paolin
- Book 1
- st
- exp6ip
- Lecture1-Introduction1
- CDF.docx
- 09. FPGA Examples
- Formulario Principal
- Crash_2012YYYY_220040703
- Eload_python automation
- JNTUK Revaluation Exam Results 280712
- mca_app

You are on page 1of 5

Chapter 1

[pg 10]The order in which functions are applied does not affect the value of the

final

result but may affect the number of operations and whether the calculation

process terminates

[pg 10 - 11]

Functional programming is a style of programming which emphasises the applicatio

n

of functions to arguments.

Specifically contrasted against the imperative style where the emphasis is on

changing stored values via assignment.

[pg 12]

Some imperative languages have a function construct, but often do not allow

first class functions (functions can be passed as arguments, returned as results

and stored in datastructures) and do not encourage generators etc.

Chapter 3 Types

Types are collections of values.

e.g: Type Bool has two values, True and False

Basic Types = Bool, Char, String, Int, Integer, Float

'Compound Types' = Lists, Tuples, Functions

Curried Functions : essentially -> associates to the right so

f :: a -> a -> a is really f :: a -> ( a -> a)

the function application operator (the empty space) associates to the left so

f 1 2 is really (f 1) 2

Currying enables partial application of functions.

KEY: Unless tupling is explicitly required all functions in Haskell are defined

as curried functions

A type that has one or more type variables is called a polymorphic type

(note: compound types include list, tuple and function types, so we can have

polymorphic tuples, lists, functions)

e.g: :t length gives length :: [a] -> Int -- before Foldable refactoring etc

so the (function) type of length is polymorphic

An expression with a polymorphic type is also polymorphic

thus length is a polymorphic function. It accepts lists of values with any type

Overloaded types are types with *constraints* on the type variables.

thus :t (+) gives (+) :: (Num a) => a -> a -> a

this says that + works on those types which are instances of the the (type)class

Num. All types in this class have numeric values.

This is interesting since 'normal' programmer talk would consider 'length' to be

an overloaded function too.

that support (== ??) an overloaded functions called methods.

iow, the types that are members of a typeclass can all be substituted for

the type variables in the type declaration of the classes methods.

Many built in typeclasses.

E.g:

Eq class contains types whose values can be compared for equality and inequality

using the following class methods

(==) :: a -> a -> Bool

(/=) :: a -> a -> Bool

All the basic types are instances of the Eq class.

List and Tuples classs are also instances of Eq provided their content types are

instances of Eq

Function types are not instances of Eq.

Ord is the typeclass of Ordered types

All instances of Eq whose values are totally (linearly) ordered.

Can be compared using the following six methods

<, <=, >, >= , which all have type a -> a -> Bool

and min and max which have type a -> a -> a

Strings, Lists and Tuples are ordered lexicographically.

Show is the typeclass of showable types and has a single method

show :: a -> String

Read is the typeclass of types which can be read from strings

read :: String -> a

read "123":: Int

The result of read is undefined if the argument is not syntactically correct

(This can lead to exceptions at run time though the program passes type checking

)

thus

not (read "False") - OK

not (read "Hello") - NOT OK

Num is the type class of numeric types. Types which are members of Eq and Show

but for which these six methods make sense

(+) ::

(-) ::

(*) ::

negate

abs ::

signum

a ->

a ->

a ->

:: a

a ->

:: a

a -> a

a -> a

a -> a

-> a

a

-> a

Integral - typeclass for those types that are members of Num but for which inte

ger

division and integer remainder make sense

div :: a -> a -> a

mod :: a -> a -> a

Int and Integer are members of Integral

Fractional - typeclass for those types that are instances of Num for which

fractional division and reciprocation make sense. Float in an instance

(/) :: a -> a -> a

(recip) :: a -> a -> a

Chapter 4 Defining Functions

- conditional expressions

abs :: Int -> Int

abs x = if x >= 0 then x else (-1) * n

- guarded equations

abs :: Int -> Int

abs x | x > 0 = x

| otherwise (-1) * x

- pattern matching

a sequence of syntactic expressions called patterns are used to choose betwee

n

results of the same type

e.g

(&&) :: Bool -> Bool -> Bool

True && True = True

True && False = False

False && True = False

False && False = False

or even better

(&&) :: Bool -> Bool -> Bool

True && True = True

_

&& _ = False

So far, for pattern matching, we used basic patterns - values, variables, or

wild card

Tuple Matching

A tuple of patterns is itself a pattern which matches any tuple of the same a

rity whose

components all match the corresponding patterns in order

e.g

fst :: (a,b) -> a

fst (x,_) = x

Similarly List Matching

A list of patterns is itself a pattern that matches any list of the same arit

y

whose components all match the corresponding patterns in order. The cons

operator can also be used in pattern matching

Thus

test

test

test

:: [Char] -> Bool

['a':_] = True

_ = False

Similarly

null [] = True

null (_:_) = False -- note that cons patterns need to be parenthesized

head (x:_) = x

tail (_:xs) = xs -- note that these two functions aren't total. hint []

- lambda expressions

alternate way of creating (anonymous) functions

(\ x -> x + 2 )

(\ x y -> x + y)

uses

1. formalize curried function definitions

add x y = x + y is really add = \x -> (\y -> x + y)

2. are useful to define functions that return functions

const :: a -> b -> a

const x _ = a

is correct but it is better expressed retuning a function

const :: a -> b -> a

const x = \ _ -> x

3. are useful to avoid naming a function

a function odds that returns the first n odd numbers

odds :: Int -> [Int]

odds n = map f [0.. (n-1)]

where f x = x * 2 + 1

works but better is

odds n = map (\ x -> x * 2 + 1) [0 .. (n-1)]

- sections

infix functions are called "operators" (e.g +)

1. any binary function can be converted into an (infix) operator by

placing it between two backticks

2. any operator can be converted into a curried function by placing it

between brackets, thus (+) . This convention also allows one of the

arguments to be included thus giving (1 +) (+ 2) etc

In general given an operator ., (.) (x .) and (. y) are called 'sections

'

Section meanings can be formalized as below

(*) = \x -> (\y -> x * y)

(x *) = \y -> (x * y)

(* y) = \x -> (x * y)

Sections have three main applications

1. very useful functions like (1+) etc

2. necessary to state the type of (infix) operators, thus

(&&) :: Bool -> Bool -> Bool

3. sections are necessary when treating operators as arguments to functi

ons

e.g : and :: [Bool] -> Bool

and = foldr (&&) True

Chapter 5 Generators

)]

Note: rightmost list gets exhausted first

Later generators can depend on variables from earlier generators.

e.g all possible ordered pairings from [1,2,3]

[(x,y) | x <- [1,2,3], y <- [x..3]]

another e.g

concat - that concatenates lists of lists can be written as

concat = [x | xs <- xss, x <- xs]

i.e one generator selects lists (from list of lists) and the next generator

selects elements from the selected list

wildcard patterns can be used to discard elements from a list

length :: [a] -> Int

length xs = sum [1 | _ <- xs]

List comprehensions can use guards to filter the stream

so map a positive integer to its factors

factors x = [y | y <- [1..x], x 'mod' y == 0]

Suppose we implement a lookup table as a list of key value pairs. Then we ca

n

look up a value (or values) associated with a key by

find :: a -> [(a,b)] -> [b]

find k t = [v | (k',v) <- t, k == k']

Ciphering

- CSP2151 Sample TestUploaded byminurajperera
- Rosario TrainingUploaded byRodrigo Caldeira
- interfacing lcd in 4bit mode with lpc2138Uploaded byhypernuclide
- Number of VariablesUploaded byyetendra singh chauhan
- Assignment Part AUploaded byraadawad
- A Concrete Approach to Learning How to ProgramUploaded byjeffreytan71
- UT Dallas Syllabus for cs1136.502 05f taught by George Steinhorst (csteinh)Uploaded byUT Dallas Provost's Technology Group
- UT Dallas Syllabus for cs1136.003 05f taught by George Steinhorst (csteinh)Uploaded byUT Dallas Provost's Technology Group
- paolinUploaded byCarlosRodrigoGutierrezMamani
- Book 1Uploaded byglhawkins
- stUploaded byKarell Useche
- exp6ipUploaded bySaumeel Gajera
- Lecture1-Introduction1Uploaded bySergio Vinsennau
- CDF.docxUploaded byJosé Martín Puga Velasco
- 09. FPGA ExamplesUploaded bypraful_kohale6642
- Formulario PrincipalUploaded byRicardo Garcia Lopez
- Crash_2012YYYY_220040703Uploaded byLothfi Alvon Rahman
- Eload_python automationUploaded by~han~
- JNTUK Revaluation Exam Results 280712Uploaded byDeweducation
- mca_appUploaded byvenkat6299
- Control TenisUploaded bychutry
- tutorial 13.docxUploaded byVictoria Love
- SAP - Evitar Clave DesarrolladorUploaded byMarcos Federico Mandrille
- Microsoft Visual Basic for ApplicationsUploaded byAnonymous vb8EJ2n
- Programming is No Longer Back to BasicsUploaded bynghiemta18
- SQL Queries FormattingUploaded byabhishek_s_gupta4753
- Eikon Cs r2 HiresUploaded byJHON MILLA
- clojure.pdfUploaded byalipiodepaula
- KeywordsUploaded byHassan Allawi
- kUploaded byAid Fatušić

- Chart Analysis RecordUploaded bymagesmail7563
- Accounting CourseUploaded bymagesmail7563
- Real World OCamlUploaded bymagesmail7563
- Pisces LibraUploaded bymagesmail7563
- Ten a Dons QuestionsUploaded bymagesmail7563
- Lenormand 1 Thru 6Uploaded bymagesmail7563
- Study Notes: Chapters 8 thru 10 of Hutton's Haskell BookUploaded bymagesmail7563
- Study Notes on Graham Hutton's Haskell Book (2nd edition)Uploaded bymagesmail7563
- Morin Lilly NotesUploaded bymagesmail7563
- Morin Notes 1Uploaded bymagesmail7563
- Notes on Solar Returns BookUploaded bymagesmail7563
- Analysis of an event chartUploaded bymagesmail7563
- Happy Tracks commentary on David Coleman's shamanistic astrology articleUploaded bymagesmail7563
- Apocalypse World Cheat SheetUploaded bymagesmail7563
- Concrete Maths Notes 1Uploaded bymagesmail7563
- Supplemental material for The 26 KeysUploaded bymagesmail7563
- Alchemy ForumUploaded bymagesmail7563
- Major planets transits for 1972 - 2032Uploaded bymagesmail7563
- The 26 Keys Practice Manual 1Uploaded bymagesmail7563
- notes on bertekas textUploaded bymagesmail7563
- Hamlet Hit Points notesUploaded bymagesmail7563
- Westeros based rpg notesUploaded bymagesmail7563
- Rpg City BuildUploaded bymagesmail7563
- Newport's stretch churn conceptUploaded bymagesmail7563
- Brandon Sanderson Writing ClassUploaded bymagesmail7563
- Notes on Jim Butcher's Writing AdviseUploaded bymagesmail7563
- Study Notes on Bell's Plot and StructureUploaded bymagesmail7563
- Notes on Thiels startup notionsUploaded bymagesmail7563
- hci_notesUploaded bymagesmail7563

- Laboratory 02 InheritanceUploaded byArelis Geraldine Guerrero
- Metacircular Semantics for Common Lisp Special FormsUploaded bystacycurl
- Using OLE Automation in Visual FoxProUploaded byCarlos N. Porras
- 2140705Uploaded by9922116408
- ch-10 Advanced relationships.pptUploaded bybhargavi
- usb_cam_logUploaded byDas Tribhubaneshwar
- CIS635_Syllabus_Spring2015Uploaded byPrawin Kumar
- 7.3 Assignment No -3Uploaded byAshish Singh
- sub_mca_512_30sep14Uploaded byBhoopendra Umrao
- 7283509-Java-Interview-QuestionUploaded bySunil Soni
- Object Oriented Programming (OOP) - CS304 Power Point Slides Lecture 37Uploaded bySameer Hane
- C Lesson PlanUploaded byphazeddl
- DiscoveringModernC++.pdfUploaded byRaafah
- Component in Software DevelopmentUploaded byTI Journals Publishing
- 340S02final(1)Uploaded by2376271
- LinkedList.hUploaded byRadenSue Raden Abd Muin
- Mockito for Spring - Sample ChapterUploaded byPackt Publishing
- Custom Annotation for Execution of Data Manipulation Commands in a Generic Manner – A Case StudyUploaded byEditor IJRITCC
- Programming in C# with Microsoft Visual Studio 2010Uploaded byVaios Villis
- Mastering ArduinoJson 6Uploaded byblitarian club
- programmes for CBSE CLASS XII practical recordsUploaded byAnil Kumar
- Dot NetUploaded bySuraj Vernekar
- Core Java Assignments lab 3Uploaded byGurjar Devyani
- mcq.docxUploaded bySaranya
- Java MCQ DocumentUploaded bySumit Tembhare
- Linked Stack RailroadUploaded byLohith Loga
- Oop Class InheritanceUploaded byp_sudheers-1
- Design Pattern Quick GuideUploaded byDavid Aziz Chusyairi
- corbaUploaded bydwnsur
- winbase_hUploaded bySambas Cahyana

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.