Using Types. Slides thanks to Mark Jones. Expressions Have Types:. The type of an expression tells you what kind of value you might expect to see if you evaluate that expression In Haskell, read “ :: ” as “has type” Examples: 1 :: Int , 'a' :: Char , True :: Bool , 1.2 :: Float , …
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Slides thanks to Mark Jones
Prelude>'a' && True
Couldn't match expected type `Bool' with actual type `Char'
In the first argument of `(&&)', namely 'a'
In the expression: 'a' && True
In an equation for `it': it = 'a' && True
Prelude>odd 1 + 2
No instance for (Num Bool)
arising from a use of `+'
Possible fix: add an instance declaration for (Num Bool)
In the expression: odd 1 + 2
In an equation for `it': it = odd 1 + 2
(1, 2) ('a', 'z') (True, False)
(1, 'z') ('a', False) (True, 2)
For any pair p, (fst p, snd p) = p
 [1, 2, 3] ['a', 'z'] [True, True, False]
*ProgrammingOutLoud> :i Num
class (Eq a, Show a) => Num a where
(+) :: a -> a -> a
(*) :: a -> a -> a
(-) :: a -> a -> a
negate :: a -> a
abs :: a -> a
signum :: a -> a
fromInteger :: Integer -> a
-- Defined in GHC.Num
instance Num Int -- Defined in GHC.Num
instance Num Integer -- Defined in GHC.Num
instance Num Double -- Defined in GHC.Float
instance Num Float -- Defined in GHC.Float