Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cameronpresley
Created June 21, 2018 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronpresley/e677f28429abf348a9a712f4628d5e1e to your computer and use it in GitHub Desktop.
Save cameronpresley/e677f28429abf348a9a712f4628d5e1e to your computer and use it in GitHub Desktop.
Chapter 6 Exercises of Haskell Book
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