Created
May 13, 2024 14:47
-
-
Save rebeccaskinner/0bb9d85901eaca132116ab89c254f6c4 to your computer and use it in GitHub Desktop.
Compare lengths of finite and infinite lists
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
data Length = forall x. Length { unLength :: [x] } | |
instance Eq Length where | |
(==) (Length []) (Length []) = True | |
(==) (Length (_:xs)) (Length (_:ys)) = Length xs == Length ys | |
(==) _ _ = False | |
instance Ord Length where | |
compare (Length []) (Length []) = EQ | |
compare (Length (_:_)) (Length []) = GT | |
compare (Length []) (Length (_:_)) = LT | |
compare (Length (_:xs)) (Length (_:ys)) = compare (Length xs) (Length ys) | |
toLength :: Length -> Int | |
toLength (Length xs) = length xs | |
length' :: [x] -> Length | |
length' = Length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment