Last active
August 3, 2023 16:47
-
-
Save CMCDragonkai/648fa627595c7ed8d26e to your computer and use it in GitHub Desktop.
Haskell: SnocList - just a list with its head up its ass
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
{-# TypeOperators #-} | |
data SnocList a = Lin | SnocList a :> a | |
listToSnocList :: [a] -> SnocList a | |
listToSnocList [] = Lin | |
listToSnocList (x : xs) = listToSnocList xs :> x | |
snocListToList :: SnocList a -> [a] | |
snocListToList Lin = [] | |
snocListToList (xs :> x) = x : snocListToList xs | |
-- get it? | |
-- Snoc | Cons | |
-- Lin | Nil | |
-- : | :> | |
-- it's just a list with the head at the back, and the tail at the front | |
-- although trivial, it shows that 2 types A, B are isomorphic to each other, | |
-- if we have morphisms f: A -> B & g: B -> A. To have such morphisms in the | |
-- type universe, the value universe needs to have possible inhabitants of such | |
-- morphism signatures | |
-- questions: | |
-- does that mean A -> B is related to B^A? | |
-- does that mean a logical language with reversible functions can have a | |
-- predicate function embodying both A -> B and B -> A?) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment