Skip to content

Instantly share code, notes, and snippets.

@jozefg
Created December 1, 2014 15:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jozefg/d790c0cd09714cc55a5c to your computer and use it in GitHub Desktop.
Save jozefg/d790c0cd09714cc55a5c to your computer and use it in GitHub Desktop.
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