Created
December 1, 2014 15:58
-
-
Save jozefg/d790c0cd09714cc55a5c to your computer and use it in GitHub Desktop.
uncons without pattern matching
This file contains hidden or 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
{-# 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