
4 Apr
2014
4 Apr
'14
6:17 p.m.
I was looking at the definition of last in the prelude and saw this code (from http://hackage.haskell.org/package/base-4.2.0.1/docs/src/GHC-List.html) -- | Extract the last element of a list, which must be finite and non-empty. last :: [a] -> a #ifdef USE_REPORT_PRELUDE last [x] = x last (_:xs) = last xs last [] = errorEmptyList "last" #else -- eliminate repeated cases last [] = errorEmptyList "last" last (x:xs) = last' x xs where last' y [] = y last' _ (y:ys) = last' y ys #endif Question: What does the second "eliminate repeated cases" definition of last gain compared to the first (simpler) one? Thanks Dimitri