Ответ 1
Определение const
есть
const x = \_ -> x
Следовательно, (const id)
- это функция, которая принимает один аргумент и всегда возвращает id
и
const id 1 2 = (\_ -> id) 1 2
= id 2
= 2
Определение foldr1
есть
foldr1 f [x] = x
foldr1 f (x:xs) = f x (foldr1 f xs)
Если мы имеем
myLast' = foldr1 (const id)
затем
myLast' [x] = foldr1 (const id) [x]
{- definition of foldr1 -}
= x
и
myLast' (x:xs) = foldr1 (const id) (x:xs)
{- definition of foldr1 -}
= (const id) x (foldr1 (const id) xs)
{- definition of const -}
= (\_ -> id) x (foldr1 (const id) xs)
{- function application -}
= id (foldr1 (const id) xs)
{- definition of id -}
= foldr1 (const id) xs
{- definition of myLast' -}
= myLast' xs
что согласуется с определением last'
.