Skip to content

Instantly share code, notes, and snippets.

@jFransham

jFransham/scott-lists.hs

Last active Sep 27, 2016
Embed
What would you like to do?
{-# LANGUAGE RankNTypes #-}
data Z
data S n
type L a = forall b. (a -> b -> b) -> b -> b
consL a fold = \cons nil -> cons a (fold cons nil)
(@:) = consL
infixr @:
nilL = \cons nil -> nil
fromList :: [a] -> L a
fromList = foldr consL nilL
showL :: Show a => L a -> String
showL fold = fold (\x rest -> show x ++ " @: " ++ rest) "nilL"
tailL :: L a -> L a
tailL fold = fst $ fold (\x (_, xs) -> (xs, x@:xs)) (undefined, nilL)
main :: IO ()
main = putStrLn $ showL $ tailL $ fromList [1, 2, 3, 4, 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment