summaryrefslogtreecommitdiff
path: root/Haskell-book/04/src/Ex.purs
blob: 38da5c4ecc082d93776216e3f31aa63eda2e270c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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