<jupyter_start><jupyter_text>Chapter 6: Typeclasses  Multiple choice The Eq class makes equality tests possible  The typeclass Ord allows any two values to be compared. The type of `>` is `Ord a => a -> a -> Bool` In `x = divMod 16 12` the type of `x` is a tuple<jupyter_code>:type divMod 16 12<jupyter_output><empty_output><jupyter_text>The typeclass Integral includes Int and Integer numbers.  Does it typecheck?<jupyter_code>data Person = Person Bool
printPerson :: Person -> IO ()
printPerson person = putStrLn (show person)
data Mood = Blah | Woot deriving Show

settleDown x = 
    if x == Woot
    then Blah
    else x
type Subject = String
type Verb = String
type Object = String

data Sentence = Sentence Subject Verb Object deriving (Eq, Show)

s1 = Sentence "dogs" "drool"
:type s1
s2 = Sentence "Julie" "loves" "dogs"
:type s2<jupyter_output><empty_output><jupyter_text>Given a datatype declaration, what can we do?<jupyter_code>data Rocks = Rocks String deriving (Eq, Show)
data Yeah = Yeah Bool deriving (Eq, Show)
data Papu = Papu Rocks Yeah deriving (Eq, Show)
phew = Papu "chases" True
truth = Papu (Rocks "chomskydoz") (Yeah True)
equalityForall :: Papu -> Papu -> Bool
equalityForall p p' = p == p'
comparePapus :: Papu -> Papu -> Bool
comparePapus p p' = p > p'<jupyter_output><empty_output><jupyter_text>Match the types<jupyter_code>i :: Num a => a
i = 1
i' :: a
i' = 1
f :: Float
f = 1.0
f' :: Num a => a
f' = 1.0
fn :: Num a => a -> a
fn a = a

fn 1.0<jupyter_output><empty_output><jupyter_text>Wtf? I can supply `1.0` as `Num a => a` for a function argument, but cannot if I try to assign it to a value with that type. That doesn't make any sense.<jupyter_code>f :: Float
f = 1.0
f' :: Fractional a => a
f' = 1.0
:info RealFrac
f' :: RealFrac a => a
f' = 1.0 
freud :: a -> a
freud x = x
freud' :: Ord a => a -> a
freud' x = x
freud' :: Int -> Int
freud' x = x
myX = 1 :: Int
sigmund :: Int -> Int
sigmund x = myX
myX = 1 :: Int
sigmund' :: a -> a
sigmund' x = myX
myX = 1 :: Int
sigmund' :: Num a => a -> a
sigmund' x = myX
myX = 1 :: Int
sigmund' :: (Num a, Num b) => a -> b
sigmund' x = myX
import Data.List

jung :: Ord a => [a] -> a
jung xs = head (sort xs)
jung :: [Int] -> Int
jung xs = head (sort xs)
young :: [Char] -> Char
young xs = head (sort xs)
young :: Ord a => [a] -> a
young xs = head (sort xs)
mySort :: [Char] -> [Char]
mySort = sort

signifier :: [Char] -> Char
signifier xs = head (mySort xs) 
mySort :: [Char] -> [Char]
mySort = sort

signifier :: Ord a => [a] -> a
signifier xs = head (mySort xs)<jupyter_output><empty_output><jupyter_text>Type-Kwon-Do Two: Electric Typealoo<jupyter_code>chk :: Eq b => (a -> b) -> a -> b -> Bool
chk a2b a b = a2b a == b
arith :: Num b => (a -> b) -> Integer -> a -> b
arith a2b i a = a2b a<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1409707351891506, 'fraction_numerical': 0.013204853675945753, 'mean_word_length': 3.6026272577996714, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '415433', 'license': 'MIT', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1078, 'n_words': 408, 'path': 'src/haskell-programming-from-first-principles/06-typeclasses.ipynb', 'repo_name': 'Eoksni/ihaskell-playground', 'size': '2802'}