Chapter 6 Exercises of Haskell Book
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.List (sort) | |
data Person = Person Bool | |
instance Show Person where | |
show (Person b) = show b | |
printPerson :: Person -> IO () | |
printPerson person = putStrLn (show person) | |
data Mood = Blah | Woot deriving (Show, Eq) | |
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" -- Will compile, but won't be shown since we haven't derived a way to Show Object->Sentence | |
s2 = Sentence "Julie" "loves" "dogs" | |
data Rocks = Rocks String deriving (Eq, Show) | |
data Yeah = Yeah Bool deriving (Eq, Show) | |
data Papu = Papu Rocks Yeah deriving (Eq, Show) | |
phew = Papu (Rocks "chases") (Yeah 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' | |
i :: Num a => a | |
i = 1 | |
f :: RealFrac a => a | |
f = 1.0 | |
freud :: Ord a => a -> a | |
freud x = x | |
freud' :: Int -> Int | |
freud' x = x | |
myX = 1 :: Int | |
sigmund :: Int -> Int | |
sigmund x = myX | |
sigmund' :: Int -> Int | |
sigmund' x = myX | |
jung :: [Int] -> Int | |
jung xs = head (Data.List.sort xs) | |
young :: Ord a => [a] -> a | |
young xs = head (Data.List.sort xs) | |
mySort :: [Char] -> [Char] | |
mySort = Data.List.sort | |
signifier :: [Char] -> Char | |
signifier xs = head (mySort xs) | |
chk :: Eq b => (a->b) -> a -> b -> Bool | |
chk f a b = f a == b | |
arith :: Num b => (a -> b) -> Integer -> a -> b | |
arith f i a = (+) (f a) (fromInteger i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment