Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active August 3, 2023 16:47
Show Gist options
  • Save CMCDragonkai/648fa627595c7ed8d26e to your computer and use it in GitHub Desktop.
Save CMCDragonkai/648fa627595c7ed8d26e to your computer and use it in GitHub Desktop.
Haskell: SnocList - just a list with its head up its ass
{-# 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