Commit: 6d3ce68bb28de716c3b5833b01326d51918d0479
Parent: 992a0cac61c9c7ab1cea01d683cc526b66a72e8a
Author: Randy Palamar
Date: Sat, 2 Dec 2023 14:21:57 -0700
remove Data.Text.pack calls everywhere
I'm sure glad the Data.Text documentation tells
you about {-# LANGUAGE OverloadedStrings #-} :/
Note: I'm purposefully not cleaning up some functions in day1 so
that it remains as a record of growth between days.
Diffstat:
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/day1/day1.hs b/day1/day1.hs
@@ -16,6 +16,8 @@
-- zoneight234 -> 14
-- (Output) 56
--
+{-# LANGUAGE OverloadedStrings #-}
+
import Data.Char
import qualified Data.Text as T
import qualified Data.Text.IO as TI
@@ -30,8 +32,8 @@ tocode st =
z = ord '0'
in 10 * (ord h - z) + (ord t - z)
-replmap :: (String, String) -> (T.Text -> T.Text)
-replmap (f, s) = T.replace (T.pack f) (T.pack s)
+replmap :: (T.Text, T.Text) -> (T.Text -> T.Text)
+replmap (f, s) = T.replace f s
repstrnums :: T.Text -> T.Text
repstrnums =
diff --git a/day2/day2.hs b/day2/day2.hs
@@ -20,19 +20,19 @@
-- each colour needed to make a game valid. Provide the sum of
-- the powers of all games.
--
+{-# LANGUAGE OverloadedStrings #-}
+
import qualified Data.Text as T
import qualified Data.Text.IO as TI
import Text.Printf (printf)
splitgame :: T.Text -> (Int, [(Int, T.Text)])
splitgame st =
- let (gn, t) = T.breakOn (T.pack ": ") st
+ let (gn, t) = T.breakOn ": " st
n = read $ T.unpack $ snd $ T.break (== ' ') gn :: Int
tuples =
map to_int_text . map (T.break (== ' ')) $
- T.splitOn (T.pack ", ") $
- T.replace (T.pack ": ") (T.pack "") $
- T.replace (T.pack ";") (T.pack ",") t
+ T.splitOn ", " $ T.replace ": " "" $ T.replace ";" "," t
in (n, tuples)
to_int_text :: (T.Text, T.Text) -> (Int, T.Text)
@@ -43,9 +43,9 @@ get_colour_list c l = map fst $ filter ((== c) . snd) l
get_rgb_triple :: [(Int, T.Text)] -> ([Int], [Int], [Int])
get_rgb_triple l =
- let r = get_colour_list (T.pack " red") l
- g = get_colour_list (T.pack " green") l
- b = get_colour_list (T.pack " blue") l
+ let r = get_colour_list " red" l
+ g = get_colour_list " green" l
+ b = get_colour_list " blue" l
in (r, g, b)
isvalidgame :: (Int, [(Int, T.Text)]) -> Int