SlideShare a Scribd company logo
Start Haskell 1st (Chapter 4)
Start Haskell 1st (Chapter 4)
isDigit :: Char -> Bool
isDigit c = c >= ‘0’ && c <= ‘9’
isDigit :: Char -> Bool
isDigit c = c >= ‘0’ && c <= ‘9’
isDigit :: Char -> Bool
isDigit c = c >= ‘0’ && c <= ‘9’
isDigit :: Char -> Bool
isDigit c = c >= ‘0’ && c <= ‘9’
isDigit :: Char -> Bool
isDigit c = c >= ‘0’ && c <= ‘9’
even :: Integral a => a -> Bool
even n = n `mod` 2 == 0
even :: Integral a => a -> Bool
even n = n `mod` 2 == 0
Start Haskell 1st (Chapter 4)
abs :: Int -> Int
abs n = if n >= 0 then n else -n
signum :: Int -> Int
signum n = if n < 0 then -1 else
        if n == 0 then 0 else 1
signum :: Int -> Int
signum n = if n < 0 then -1 else
        if n == 0 then 0 else 1
Start Haskell 1st (Chapter 4)
abs n | n >= 0 = n
______| otherwise = -n
abs n | n >= 0 = n
______| otherwise = -n
abs n | n >= 0 = n
______| otherwise = -n
abs n | n >= 0 = n
______| otherwise = -n
signum n | n < 0    = -1
_________| n == 0 = 0
_________| otherwise = 1
Start Haskell 1st (Chapter 4)
Start Haskell 1st (Chapter 4)
not :: Bool -> Bool
not False = True
not True = False
not :: Bool -> Bool
not False = True
not True = False
not :: Bool -> Bool
not False = True
not True = False
(&&) :: Bool -> Bool -> Bool
True && True = True
True && False = False
False && True = False
False && False = False
(&&) :: Bool -> Bool -> Bool
True && True = True
_ && _ = False
(&&) :: Bool -> Bool -> Bool
True && b = b
False && _ = False
(&&) :: Bool -> Bool -> Bool
True && b = b
False && _ = False
(&&) :: Bool -> Bool -> Bool
True && b = b
False && _ = False
b && c | b == c = b
_______| otherwise = False
fst :: (a,b) -> a
fst (x,_) = x
test :: [Char] -> Bool
test ['a',_,_] = True
test _        = False
Start Haskell 1st (Chapter 4)
Start Haskell 1st (Chapter 4)
[1,2,3] = 1:[2,3]
________= 1:(2:[3])
________= 1:(2:(3:[]))
[1,2,3] = 1:[2,3]
________= 1:(2:[3])
________= 1:(2:(3:[]))
[1,2,3] = 1:[2,3]
________= 1:(2:[3])
________= 1:(2:(3:[]))
________= 1:2:3:[]
Start Haskell 1st (Chapter 4)
test :: [Char] -> Bool
test ('a':_) = True
test _       = False
test :: [Char] -> Bool
test ('a':_) = True
test _       = False
Start Haskell 1st (Chapter 4)
Start Haskell 1st (Chapter 4)
Start Haskell 1st (Chapter 4)
x -> x + x
double x = x + x
Start Haskell 1st (Chapter 4)
add :: (Int,Int) -> Int
add x y = x + y
add :: Int -> Int -> Int
add x y = x + y
add :: Int -> (Int -> Int)
add x -> (y -> x + y)
const :: a -> b -> a
const x _ = x
const :: a -> (b -> a)
const x = _ -> x
odds :: Int -> [Int]
odds n = map f [0..n-1]
     where f x = x * 2 + 1
odds :: Int -> [Int]
odds n = map (x -> x*2+1)[0..n-1]
Start Haskell 1st (Chapter 4)
Start Haskell 1st (Chapter 4)
(+) :: Num a => a -> a -> a
(+) = x -> (y -> x + y)
(+1) = x -> x + 1
(1+) = y -> 1 + y
(+) = x -> (y -> x + y)
(+1) = x -> x + 1
(1+) = y -> 1 + y
and :: [Bool] -> Bool
and = foldr (&&) True
Start Haskell 1st (Chapter 4)
Start Haskell 1st (Chapter 4)
Start Haskell 1st (Chapter 4)
Start Haskell 1st (Chapter 4)
Start Haskell 1st (Chapter 4)

More Related Content

PPTX
Warehouse layout design
DOCX
Revision sheet 1 g9
PPTX
January 23, 2015
DOCX
Examen du premier semestre g9
PDF
ZipCode_Distance_by_Agent_Home_Zip_2015091501
PPTX
Mod 4 Project by Mateo C
PPTX
Methods3 types of functions1
ZIP
Rakudo Star at Yapcasia2010
Warehouse layout design
Revision sheet 1 g9
January 23, 2015
Examen du premier semestre g9
ZipCode_Distance_by_Agent_Home_Zip_2015091501
Mod 4 Project by Mateo C
Methods3 types of functions1
Rakudo Star at Yapcasia2010

Similar to Start Haskell 1st (Chapter 4) (19)

PPTX
Complex numbers
PDF
Intro To Agda
PDF
Programming for Problem Solving
ODP
Approximate Matching (String Algorithms 2007)
PPTX
Peretmuan iii iv sistem bilangan ( bagian pertama )
PDF
Haskell Tour (Part 2)
PPTX
C - programming - Ankit Kumar Singh
PDF
JavaScript Past, Present and Future
PPT
18. simpl met-algebraicos
PPT
simplificacion metodos-algebraicos
PPT
18. simpl met-algebraicos
PPT
18. simpl met-algebraicos
PPT
Métodos de simplificación
PPT
Simplificación funciones Booleanas
PDF
Chapter0
PDF
CULEGERE INFORMATICA cu probleme rezolvate
PPT
M8 al if-1
PDF
Search-based Unit Test Generation with EvoSuite
PDF
Exercicis Electrònica Digital BATXILLERAT
Complex numbers
Intro To Agda
Programming for Problem Solving
Approximate Matching (String Algorithms 2007)
Peretmuan iii iv sistem bilangan ( bagian pertama )
Haskell Tour (Part 2)
C - programming - Ankit Kumar Singh
JavaScript Past, Present and Future
18. simpl met-algebraicos
simplificacion metodos-algebraicos
18. simpl met-algebraicos
18. simpl met-algebraicos
Métodos de simplificación
Simplificación funciones Booleanas
Chapter0
CULEGERE INFORMATICA cu probleme rezolvate
M8 al if-1
Search-based Unit Test Generation with EvoSuite
Exercicis Electrònica Digital BATXILLERAT
Ad

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Electronic commerce courselecture one. Pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
KodekX | Application Modernization Development
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Encapsulation theory and applications.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Empathic Computing: Creating Shared Understanding
Mobile App Security Testing_ A Comprehensive Guide.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Dropbox Q2 2025 Financial Results & Investor Presentation
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Electronic commerce courselecture one. Pdf
Spectral efficient network and resource selection model in 5G networks
“AI and Expert System Decision Support & Business Intelligence Systems”
Reach Out and Touch Someone: Haptics and Empathic Computing
Diabetes mellitus diagnosis method based random forest with bat algorithm
20250228 LYD VKU AI Blended-Learning.pptx
Big Data Technologies - Introduction.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
KodekX | Application Modernization Development
NewMind AI Monthly Chronicles - July 2025
Encapsulation theory and applications.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Network Security Unit 5.pdf for BCA BBA.
Encapsulation_ Review paper, used for researhc scholars
Empathic Computing: Creating Shared Understanding
Ad

Start Haskell 1st (Chapter 4)

Editor's Notes