






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This course is an introduction to concepts in programming languages. The course covers a range of programming paradigms including procedural, functional, and logic-based languages. This lecture includes: Haskell and Function Types, Basic Haskell Types, Boolean Values, Instances Are Types, Whole Number Types, Class Constraints, Function Types
Typology: Study notes
1 / 10
This page cannot be seen from the preview
Don't miss anything!







Today’s Topics ...
Reminder ...
Char
Bool
Int
Double
Haskell Type Classes
As we’ve seen, types are more complicated for numbers ...
Prelude> :type 49 49 :: (Num t) => t
Num ... number types (must be in Eq and Show)
Integral ...whole number types (Int and Integer)
Bounded, Floating, Fractional, Real, RealFrac
For this type ...
Prelude> :type 49 49 :: (Num t) => t
Functions have types (either given or inferred)
Prelude> not True False
Prelude> :type not not :: Bool -> Bool
“not has the type Bool to Bool”
“not takes a Bool and returns a Bool”
Another example
Prelude> succ 6 7
Prelude> :type succ succ :: (Enum a) => a -> a
“for all Enum types a, succ has the type a to a”
Example
Prelude> take 4 [1, 3 .. 21] [1, 3, 5, 7]
Prelude> :type take take :: Int -> [a] -> [a]
For now you can view the function as ...
But why two -> (to) symbols?
Allows us to define partial applications of the function
Prelude> let take4 x = take 4 x
Prelude> :t take take4 :: [a] -> [a]
Prelude> take4 [1, 3 .. 21] [1, 3, 5, 7]
take :: Int -> [a] -> [a] take4 :: [a] -> [a]
What are the types of these functions?
Prelude> null [5] null :: [a] -> Bool False
Prelude> lines "Hello\nWorld" lines :: String -> [String] ["Hello", "World"]
Prelude> take 5 [1..10] take :: Int -> [a] -> [a] [1, 2, 3, 4, 5]
Prelude> replicate 5 ’a’ replicate :: Int -> a -> [a] "aaaaa"
Although Haskell can infer them for you ...
add :: (Num a) => a -> a -> a add x y = x + y