of a list without
using last
last' ::
(a) - a last" : (a) - a
last' [] = error 'erro' last" [] + error
last'[x] = last"(x) = x
last' (x: xs) = last' as last" = .
head reverse
2) last but one element of the list
but Last :: (a] -
a butlast' : [a] - a
but Last [b ,
-j =
b but Last' = reverses !!
but Last (- : (s) =
butLast as
3) kth element
of a list but the first element is 1.
kthFromone :: (a] - Int-a
kthFromone list k = list !! (k 1) -
4) Product a list of numbers
myProd Num :: a = (a] - a
my
Prod' Num : a => [a] -a
myProd[] 1 =
myRod' 5] =
1
myProd (x : (s) = x
*
(myProd(s) myProd' (x xs) : = ( *) x (myProd'xs)
5) Produces a list
of the first n integrer that are squares
squareUpto :: Int- (Int] SquareUpto' :: Int- [Int]
squareupto n =
(x 2(x =
(1 ... n]] squareupton = take n[x 2)x =
(1 ...
3]
6) produces a list
of ist - squars and smaller than a
given value
squareSmaller :: Int- (Int]
squarsmalle n =
[y) y
=
SquaresUpton ,
y< n]
7) function that splits an
even-length list into two halves
halve :· (a) +
((a) (a]) ,
halve xs -
(take n Xs , drop n xs)
where 'div'2
n =
length as
5) function that uturn third element in a list
third :: [a) - a third' : [a] + a third" :: [a] - a
third <S = head (tail (tail(s) third'us =s !! 2 third") - : - : -) =
↳ third-head .tail tail .