aboutsummaryrefslogtreecommitdiff
path: root/ch01_01.4-iii.hs
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2025-01-03 11:01:20 -0800
committerPaul Oliver <contact@pauloliver.dev>2025-01-05 09:59:10 -0800
commit6a0d7f5c434c3564d0119befb6799fd77581050a (patch)
treef20bc998290211d2a895523417ad32e297b31af0 /ch01_01.4-iii.hs
InitialHEADmaster
Diffstat (limited to 'ch01_01.4-iii.hs')
-rw-r--r--ch01_01.4-iii.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/ch01_01.4-iii.hs b/ch01_01.4-iii.hs
new file mode 100644
index 0000000..78885aa
--- /dev/null
+++ b/ch01_01.4-iii.hs
@@ -0,0 +1,14 @@
+-- Exercise 1.4-iii
+-- Prove `(a * b)^c == a^c * b*c`.
+func2Tup :: (c -> (a, b)) -> (c -> a, c -> b)
+func2Tup f = (fst . f, snd . f)
+
+-- This version takes in a tuple of functions, which is equivalent to them
+-- being separate arguments:
+tup2Func :: (c -> a, c -> b) -> c -> (a, b)
+tup2Func (f, g) v = (f v, g v)
+
+-- This version has the same signature as Sandy's version, and calls `curry`
+-- against my tupled rendition above:
+tup2Func' :: (c -> a) -> (c -> b) -> c -> (a, b)
+tup2Func' = curry tup2Func