Skip to content

Commit 0f7d15e

Browse files
committed
liftA2 is the same as liftM2
1 parent fcb5e3d commit 0f7d15e

File tree

4 files changed

+5
-10
lines changed

4 files changed

+5
-10
lines changed

02.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import Text.Parsec
2-
import Text.Parsec.String (Parser)
3-
import Control.Applicative (liftA2)
42

53
main :: IO ()
6-
main = interact $ (++"\n") . show . liftA2 (,) p1 p2 . parseGames
4+
main = interact $ (++"\n") . show . ((,) <$> p1 <*> p2) . parseGames
75

86
data Game = Game { gid :: Int, draw :: Draw } deriving Show
97
data Draw = Draw { red :: Int, green :: Int, blue :: Int } deriving Show

03.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import Control.Applicative (asum, liftA2)
1+
import Control.Applicative (asum)
22
import Control.Monad (guard)
33
import Data.Char (isDigit)
44
import Data.Map qualified as M
55
import Data.Maybe (catMaybes, isJust, fromJust, isNothing)
66

77
main :: IO ()
8-
main = interact $ (++ "\n") . show . liftA2 (,) p1 p2 . parseParts
8+
main = interact $ (++ "\n") . show . ((,) <$> p1 <*> p2) . parseParts
99

1010
data Grid = Grid { rows :: [String], my :: Int, mx :: Int }
1111

04.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{-# LANGUAGE LambdaCase #-}
22

3-
import Control.Applicative (liftA2)
43
import Control.Monad.State
54
import Data.Map qualified as M
65
import Text.Parsec hiding (State)
7-
import Text.Parsec.String (Parser)
86

97
-- Use Parsec to parse, and the State monad to memoize
108
--
@@ -13,7 +11,7 @@ import Text.Parsec.String (Parser)
1311
-- https://mrmr.io/memoization-in-haskell
1412

1513
main :: IO ()
16-
main = interact $ (++ "\n") . show . liftA2 (,) p1 p2 . parseCards
14+
main = interact $ (++ "\n") . show . ((,) <$> p1 <*> p2) . parseCards
1715

1816
data Card = Card { winning :: [Int], have :: [Int] } deriving (Show)
1917

05.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import Text.Parsec
22
import Text.Parsec.String (Parser)
33
import Control.Monad (void)
4-
import Control.Applicative (liftA2)
54

65
main :: IO ()
7-
main = interact $ (++ "\n") . show . liftA2 (,) p1 p2 . parseAlmanac
6+
main = interact $ (++ "\n") . show . ((,) <$> p1 <*> p2) . parseAlmanac
87

98
data Almanac = Almanac { seeds :: [Int], maps :: [RangesMap] } deriving Show
109
type RangesMap = [RangeMap]

0 commit comments

Comments
 (0)