Hi,
I am learning Haskell and I come from an imperative programming language background.
I am trying to re implement some functions in the Data.List
ghc library like head :
head :: [a] -> a
But when ran with an empty list it should throw an exception :
Prelude> head []
*** Exception: Prelude.head: empty list
This is fairly simple but I have this :
head :: [a] -> a
head [] = ??
head (x:xs) = x
How can I implement something similar in Haskell? I tried to look at the source code but it uses rather complicated structures and use a raise#
function that I can’t find in the documentation.
Thanks!