Skip to content

Instantly share code, notes, and snippets.

@jozefg

jozefg/Tail.hs

Created Dec 1, 2014
Embed
What would you like to do?
uncons without pattern matching
{-# LANGUAGE ImpredicativeTypes #-}
{-# LANGUAGE RankNTypes #-}
module Tail where
type CL a = forall c. (a -> c -> c) -> c -> c
t :: CL a -> (forall c. (a -> (Bool -> c) -> (Bool -> c))
-> (Bool -> c)
-> (Bool -> c))
t fold cons nil = fold myCons myNil
where myNil = nil
myCons _ as True = as False
myCons a as False = cons a (\_ -> as False) False
ctail :: CL a -> CL a
ctail l cons nil = t l (\x xs b -> cons x (xs b)) (\_ -> nil) True
chead :: CL a -> a
chead l = l const undefined
uncons :: CL a -> (a, CL a)
uncons l = (chead l, ctail l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.