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/04/src/Ex.purs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Haskell-book/04/src/Ex.purs (limited to 'Haskell-book/04/src/Ex.purs') diff --git a/Haskell-book/04/src/Ex.purs b/Haskell-book/04/src/Ex.purs new file mode 100644 index 0000000..38da5c4 --- /dev/null +++ b/Haskell-book/04/src/Ex.purs @@ -0,0 +1,33 @@ +module Ex where + +import Prelude +import Data.Array (tail, reverse) +import Data.Maybe (Maybe(..)) +import Data.String (toCharArray) +import Data.Tuple (fst, snd, Tuple(..)) + +awesome :: Array String +awesome = ["Papuchon", "curry", ":)"] + +alsoAwesome :: Array String +alsoAwesome = ["Quake", "The Simons"] + +allAwesome :: Array (Array String) +allAwesome = [awesome, alsoAwesome] + +length :: forall a. Array a -> Int +length n = length' 0 (tail n) + where length' i Nothing = i + length' i (Just k) = length' (i + 1) (tail k) + +isPalindrome :: String -> Boolean +isPalindrome x = toCharArray x == reverse (toCharArray x) + +myAbs :: Int -> Int +myAbs a = if a > 0 then a else -a + +f :: forall a b c d. Tuple a b -> Tuple c d -> Tuple (Tuple b d) (Tuple a c) +f x y = Tuple (Tuple (snd x) (snd y)) (Tuple (fst x) (fst y)) + +f' :: forall a b. (Tuple a b) -> a +f' (Tuple a b) = a -- cgit v1.2.3