From 3624c712d72d246f21d4e710cec7c11e052e0326 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 9 Dec 2025 16:32:32 +0100 Subject: Add the haskell book --- Haskell-book/03/src/Main.purs | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Haskell-book/03/src/Main.purs (limited to 'Haskell-book/03/src') diff --git a/Haskell-book/03/src/Main.purs b/Haskell-book/03/src/Main.purs new file mode 100644 index 0000000..d73dc74 --- /dev/null +++ b/Haskell-book/03/src/Main.purs @@ -0,0 +1,45 @@ +module Main where + +import Prelude +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Console (CONSOLE, log) +import Data.String (singleton, drop, take) +import Data.String.Unsafe (charAt) + +-- Given +-- "Curry is awesome" +-- Return +-- "Curry is awesome!" +a :: String -> String +a x = x <> "!" + +-- Given +-- "Curry is awesome!" +-- Return +-- "y" +b :: String -> String +b x = singleton $ charAt 4 x + +-- Given +-- "Curry is awesome!" +-- Return +-- "awesome!" +c :: String -> String +c = drop 9 + +-- If you apply your function to this value: +-- "Curry is awesome" +-- Your function should return +-- 'r' +thirdLetter :: String -> Char +thirdLetter = charAt 2 + +letterIndex :: Int -> Char +letterIndex x = charAt x "Curry is awesome!" + +rvrs :: String -> String +rvrs inp = (drop 9 inp) <> (drop 5 $ take 9 inp) <> (take 5 inp) + +main :: forall e. Eff (console :: CONSOLE | e) Unit +main = do + log $ rvrs "Curry is awesome" -- cgit v1.2.3