test like this
Prelude> let f :: a -> a -> a -> a; f = undefined
Prelude> :t f undefined
f undefined :: a -> a -> a
Prelude> :t f 1
f 1 :: Num a => a -> a -> a
Prelude> :t f (1 :: Int)
f (1 :: Int) :: Int -> Int -> Int
-
a)
f :: a -> a -> a -> a f 'a' :: Char -> Char -> Char
-
d)
g :: a -> b -> c -> b g 0 'c' "woot" :: Char
-
d)
h :: (Num a, Num b) => a -> b -> b h 1.0 2 :: Num b => b
-
c)
h :: (Num a, Num b) => a -> b -> b h 1 (5.5 :: Double) :: Double
-
a)
jackal :: (Ord a, Eq b) => a -> b -> a jackal "keyboard" "has the word jackal in it" :: [Char]
-
e)
jackal :: (Ord a, Eq b) => a -> b -> a jackal "keyboard" "has the word jackal in it" :: Eq b => b -> [Char]
-
d)
kessel :: (Ord a, Num b) => a -> b -> a kessel 1 2 :: (Num a, Ord a) => a
-
a)
kessel :: (Ord a, Num b) => a -> b -> a kessel 1 (2 :: Integer) :: (Num a, Ord a) => a
-
c)
kessel :: (Ord a, Num b) => a -> b -> a kessel (1 :: Integer) 2 :: Integer
-
[Char] → [Char]
(++) :: [a] -> [a] -> [a] myConcat x = x ++ " yo"
-
Fractional a ⇒ a → a
(*) :: Num a => a -> a -> a myMult x = (x / 3) * 5
-
Int → [Char]
take :: Int -> [a] -> [a] myTake x = take x "hey you"
-
Int → Bool
(>) :: Ord a => a -> a -> Bool myCom x = x > (length [1..10])
-
Char → Bool
(<) :: Ord a => a -> a -> Bool myAlph x = x < 'z'
-
c) value of type
[a]
is a list whose elements are all of some typea
-
a) function of type
[[a]] → [a]
could take a list of strings as an argument -
b) function of type
[a] → Int → a
returns one element of typea
from a list -
c) function of type
(a, b) → a
takes a tuple argument and returns the first value
-
return value and type
-
54 :: Num a ⇒ a
-
(0, "doge) :: Num t ⇒ (t, [Char])
-
(0, "doge) :: (Integer, [Char])
-
False :: Bool
-
5 :: Int
-
False :: Bool
-
-
type is
Num a ⇒ a
-
y
is shadowed, type isNum a ⇒ a → a
-
type is
Fractional ⇒ a :: a
-
type is
[Char]
-
wahoo = bigNum $ 10
breaks, becausebigNum
is a value, not a function -
works fine in GHCI, should work too in file
-
breaks on
c = b 10
,b
has value5
, cannot apply value to a value -
breaks on
b = 10000 * c
,c
is not defined
-
f :: zed → Zed → Blah
is fully polymorphic, concrete and concrete -
f :: Enum b ⇒ a → b → C
is fully polymorphic, constrained polymorphic and concrete -
f :: f → g → C
is fully polymorphic, fully polymorphic and concrete
-
functionH (x:_) = x
type signaturefunctionH :: [a] → a
-
functionC x y = if (x > y) then True else False
type signaturefunctionC :: Ord a ⇒ a → a → Bool
-
functionS (x, y) = y
type signaturefunctionS :: (a, b) → b
-
i :: a → a; i a = a
orid
-
c :: a → b → a; c a _ = a
-
c'' :: b → a → b; c :: a → b → a
they are the same -
c' :: a → b → b; c _ b = b
-
r :: [a] → [a]
possiblyr a = tail a
orr a = reverse a
-
co :: (b → c) → (a → b) → (a → c); co = (.)
-
a :: (a → c) → a → a; a f x = x
basically ignore the first argument -
a' :: (a → b) → a → b; a' = ($)
link:ch05_5.9_0.hs[role=include]
link:ch05_5.9_1.hs[role=include]
link:ch05_5.9_2.hs[role=include]
full example for this section, it is al only about type checking
link:ch05_5.9_3.hs[role=include]
-
just a composition
link:ch05_5.9_4.hs[role=include]
-
also a composition
link:ch05_5.9_5.hs[role=include]
-
once u got the point, it is kinda easy
link:ch05_5.9_6.hs[role=include]
-
neat
link:ch05_5.9_7.hs[role=include]