Created
June 1, 2013 22:07
-
-
Save fatho/5691869 to your computer and use it in GitHub Desktop.
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
import Prelude hiding ((++)) | |
import qualified Prelude as P | |
class ListLike a where | |
(++) :: a b -> a b -> a b | |
(<:) :: b -> a b -> a b | |
(>:) :: a b -> b -> a b | |
nil :: a b | |
newtype L a = L ([a] -> [a]) | |
unL :: L a -> [a] -> [a] | |
unL (L f) = f | |
toList :: L a -> [a] | |
toList f = (unL f) [ ] | |
instance ListLike [] where | |
(++) = (P.++) | |
(<:) = (:) | |
(>:) xs x = xs ++ [x] | |
nil = [] | |
instance ListLike L where | |
(++) f g = L (unL f . unL g) | |
(<:) x f = L ((x:) . unL f) | |
(>:) f x = L (unL f . (x:)) | |
nil = L id | |
reverse'' :: [a] -> L a | |
reverse'' [] = nil | |
reverse'' (x:xs) = (reverse'' xs) >: x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment