module Solutions.P04 (myLength, myLength', myLength'', myLength''') where
myLength :: [a] -> Int
myLength :: forall a. [a] -> Int
myLength [] = Int
0
myLength (a
_:[a]
xs) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [a] -> Int
forall a. [a] -> Int
myLength [a]
xs
myLength' :: [a] -> Int
myLength' :: forall a. [a] -> Int
myLength' = [a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length
myLength'' :: [a] -> Int
myLength'' :: forall a. [a] -> Int
myLength'' [a]
l = [Int] -> Int
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([Int] -> Int) -> [Int] -> Int
forall a b. (a -> b) -> a -> b
$ (a -> Int) -> [a] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> a -> Int
forall a b. a -> b -> a
const Int
1) [a]
l
myLength''' :: [a] -> Int
myLength''' :: forall a. [a] -> Int
myLength''' [a]
l = [a] -> Int -> Int
forall {t} {a}. Num t => [a] -> t -> t
accumulate [a]
l Int
0
where accumulate :: [a] -> t -> t
accumulate [] t
n = t
n
accumulate (a
_:[a]
xs) t
n = [a] -> t -> t
accumulate [a]
xs (t
nt -> t -> t
forall a. Num a => a -> a -> a
+t
1)