I’ve started learning Haskell with the free online book Real World Haskell by Bryan O’Sullivan, Don Stewart, and John Goerzen. Exercise 2 in Chapter 2 Types and Functions asks for a function called lastbutone that returns the second last element in a collection of elements. Here’s a first version using conditional:

```-- lastbutone-1.hs
-- Return the penultimate element, i.e. the element before the last element.
lastbutone :: [a] -> a
lastbutone xs =
if (length xs) == 1 || null xs then
else
head (drop ((length xs) - 2) xs)
```

And a sample interactive session:

```ghci> :load lastbutone-1.hs
[1 of 1] Compiling Main             ( lastbutone-1.hs, interpreted )
ghci> lastbutone [1, 2, 3, 4]
3
ghci> lastbutone [1, 2, 3]
2
ghci> lastbutone [1, 2]
1
ghci> lastbutone [1]
1
ghci> lastbutone []
```

Here’s another version without conditional and using only head, tail, and reverse:

```-- lastbutone-2.hs
-- Return the penultimate element, i.e. the element before the last element.
lastbutone :: [a] -> a
lastbutone xs =
```

And a sample interactive session:

```ghci> :load lastbutone-2.hs
[1 of 1] Compiling Main             ( lastbutone-2.hs, interpreted )
ghci> lastbutone [1, 2, 3, 4]
3
ghci> lastbutone [1, 2, 3]
2
ghci> lastbutone [1, 2]
1
ghci> lastbutone [1]