Created
September 27, 2025 00:31
-
-
Save emilypi/ab00564d2be6d5ba549a74593d0f89cd to your computer and use it in GitHub Desktop.
GPT-5 Problem
This file contains hidden or 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
| 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