Created
January 29, 2020 22:05
-
-
Save monadplus/839b2f73f21bd2ec75e397f42f1e9e34 to your computer and use it in GitHub Desktop.
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
-- | a. Fix that for me - write a list that allows me to hold any functions as | |
-- long as the input of one lines up with the output of the next. | |
data TypeAlignedList a b where | |
TNil :: TypeAlignedList a a | |
TCons :: (a -> r) -> TypeAlignedList r b -> TypeAlignedList a b | |
-- >>> f = TCons (+2) (TCons show TNil); f :: TypeAlignedList Int String | |
-- | b. Which types are existential? | |
-- r | |
-- | c. Write a function to append type-aligned lists. This is almost certainly | |
-- not as difficult as you'd initially think. | |
composeTALs :: TypeAlignedList b c -> TypeAlignedList a b -> TypeAlignedList a c | |
composeTALs bc TNil = bc -- a ~ b => TypeAlignedList b c ~ TypeAlignedList a c | |
composeTALs bc (TCons ax txb) = TCons ax (composeTALs bc txb) | |
evalTAL :: TypeAlignedList a b -> (a -> b) | |
evalTAL TNil = id | |
evalTAL (TCons ax txb) = evalTAL txb . ax | |
-- >>> f = (TCons show TNil); f :: TypeAlignedList Int String | |
-- >>> g = (TCons read TNil); g :: TypeAlignedList String Int | |
-- >>> gof = composeTALs g f | |
-- (evalTAL gof) 1234 | |
-- 1234 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment