Created
June 20, 2017 15:50
-
-
Save sdleffler/734fe400dbcb997b6f99049c55c8aed7 to your computer and use it in GitHub Desktop.
LiquidHaskell interaction with optimized Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | 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 | |
-- Use foldl to make last a good consumer. | |
-- This will compile to good code for the actual GHC.List.last. | |
-- (At least as long it is eta-expaned, otherwise it does not, #10260.) | |
last xs = foldl (\_ x -> x) lastError xs | |
{-# INLINE last #-} | |
-- The inline pragma is required to make GHC remember the implementation via | |
-- foldl. | |
lastError :: a | |
lastError = errorEmptyList "last" | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment