Skip to content

Instantly share code, notes, and snippets.

@fatho
Created June 1, 2013 22:07
Show Gist options
  • Save fatho/5691869 to your computer and use it in GitHub Desktop.
Save fatho/5691869 to your computer and use it in GitHub Desktop.
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