commit 6deb6ea78e5eef79e7b9724f534bd5b5297bcf2e
parent e3c1d87b19b9e6cb78b0b6e3aa8f87e669f27119
Author: Andrew Laack <andrew.laack@imbue.com>
Date: Mon, 10 Nov 2025 18:05:35 -0600
Continued working through the book
Diffstat:
5 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/ch1/composition.hs b/ch1/composition.hs
@@ -0,0 +1,18 @@
+-- addOne num = num + 1
+-- timesTwo num = num * 2
+-- squared num = num * num
+-- minusFive num = num - 5
+--
+-- result1 = addOne 1
+-- result2 = timesTwo result1
+-- result3 = squared result2
+--
+-- main = print (minusFive result3)
+
+addOne num = num + 1
+timesTwo num = num * 2
+squared num = num * num
+minusFive num = num - 5
+findResult num = minusFive (squared (timesTwo (addOne num)))
+
+main = print (findResult 7)
diff --git a/ch1/function-composition-operator.hs b/ch1/function-composition-operator.hs
@@ -0,0 +1,6 @@
+addOne num = num + 1
+timesTwo num = num * 2
+
+timesTwoPlusOne = timesTwo . addOne
+
+main = print $ timesTwoPlusOne 10
diff --git a/ch1/partially-applied.hs b/ch1/partially-applied.hs
@@ -0,0 +1,7 @@
+module Main where
+
+greet message person = print (message <> " " <> person)
+
+greeting = greet "Hello"
+
+main = greeting "Andrew"
diff --git a/ch1/pointfree.hs b/ch1/pointfree.hs
@@ -0,0 +1,5 @@
+makeGreeting salutation person = salutation <> " " <> person
+-- makeGreeting' salutation = ((salutation <> " ") <>)
+
+makeGreeting' salutation = (<>) (salutation <> " ")
+
diff --git a/ch1/printPair.hs b/ch1/printPair.hs
@@ -0,0 +1,11 @@
+double = (2*)
+halve = (/2)
+
+doubleTen = double 10
+halfTen = halve 10
+
+printFirst a = putStr (show (fst a))
+printSecond a = putStr (show (snd a))
+printPair a = putStr "(" >> printFirst a >> putStr ", " >> printSecond a >> putStr ")\n"
+
+main = printPair (10, 20)