Skip to content

Instantly share code, notes, and snippets.

@emilypi
Created September 27, 2025 00:31
Show Gist options
  • Select an option

  • Save emilypi/ab00564d2be6d5ba549a74593d0f89cd to your computer and use it in GitHub Desktop.

Select an option

Save emilypi/ab00564d2be6d5ba549a74593d0f89cd to your computer and use it in GitHub Desktop.
GPT-5 Problem
module Main
( main
) where
-- | Reverse a list.
--
-- Subject to the following laws:
--
-- * reverse' . reverse' = id
--
reverse' :: [a] -> [a]
reverse' x = undefined
-- | Implement reverse' such that main both compiles and produces values.
--
-- Hint: use laziness to your advantage. Define an auxiliary function, say,
--
-- `reverse'' :: Int -> [a] -> [a] -> [a]`
--
-- that can recurse along in finite chunks of size `n`, weaving `take` and `drop` values
-- into an accumulator.
--
main :: IO ()
main = do
print $ reverse' $ [1..10]
print $ length . take 1 . reverse' . reverse' $ [1..]
print $ length . take 50000 . reverse' . reverse' $ [1..]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment