From 96103ea6651abb46981b858b87c641c97e833478 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sun, 31 Dec 2023 16:03:39 +0100 Subject: [PATCH] Blah --- makefile | 3 +++ src/Main.purs | 36 +++++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/makefile b/makefile index 88ef785..9a94ee3 100644 --- a/makefile +++ b/makefile @@ -2,3 +2,6 @@ all: build build: spago build + +run: + spago run diff --git a/src/Main.purs b/src/Main.purs index f52c585..f74f291 100644 --- a/src/Main.purs +++ b/src/Main.purs @@ -42,12 +42,18 @@ instance bindParser :: Bind Parser where let (Parser p2) = f x in p2 xs +charP :: Char -> Parser Boolean +charP c = (_ == c) <$> itemP + isf :: Parser Boolean isf = (_ == 'f') <$> itemP isf2 :: Parser Boolean isf2 = (==) <$> itemP <*> pure 'f' +isf3 :: Parser Boolean +isf3 = charP 'f' + ishi :: Parser (Tuple Boolean Boolean) ishi = Tuple <$> ((_ == 'h') <$> itemP) <*> ((_ == 'i') <$> itemP) @@ -68,25 +74,25 @@ main :: Effect Unit main = do log "🍝" - case parse ishi2 "hi" of - Just (Tuple x y) -> log ("parsing 'hi': " <> show x <> " " <> show y) - Nothing -> log "coudn't parse two letters" + log $ "parsing 'hi': " <> case parse ishi2 "hi" of + Just (Tuple x y) -> show x <> " " <> show y + Nothing -> "coudn't parse two letters" - case parse ishi2 "no" of - Just (Tuple x y) -> log ("parsing 'no': " <> show x <> " " <> show y) - Nothing -> log "coudn't parse two letters" + log $ "parsing 'no': " <> case parse ishi2 "no" of + Just (Tuple x y) -> show x <> " " <> show y + Nothing -> "coudn't parse two letters" - case parse ishi2 "ho" of - Just (Tuple x y) -> log ("parsing 'ho': " <> show x <> " " <> show y) - Nothing -> log "coudn't parse two letters" + log $ "parsing 'ho': " <> case parse ishi2 "ho" of + Just (Tuple x y) -> show x <> " " <> show y + Nothing -> "coudn't parse two letters" - case parse ishi2 "ni" of - Just (Tuple x y) -> log ("parsing 'ni': " <> show x <> " " <> show y) - Nothing -> log "coudn't parse two letters" + log $ "parsing 'ni': " <> case parse ishi2 "ni" of + Just (Tuple x y) -> show x <> " " <> show y + Nothing -> "coudn't parse two letters" - case parse ishi2 "" of - Just (Tuple x y) -> log ("parsing '': " <> show x <> " " <> show y) - Nothing -> log "coudn't parse two letters" + log $ "parsing '': " <> case parse ishi2 "" of + Just (Tuple x y) -> show x <> " " <> show y + Nothing -> "coudn't parse two letters" -- JUST WORKS