Skip to content

Instantly share code, notes, and snippets.

@ijp
Last active September 12, 2024 00:14
Show Gist options
  • Save ijp/960a192ead1c24888701314ff837bf6f to your computer and use it in GitHub Desktop.
Save ijp/960a192ead1c24888701314ff837bf6f to your computer and use it in GitHub Desktop.
K2 PCA in Haskell
import Prelude hiding (lookup)
import Data.Maybe
type Nat = Int -- !!
type Baire = Nat -> Maybe Nat
encode :: [Maybe Nat] -> Nat
encode = undefined
lookup :: Baire -> Baire -> Maybe Nat
lookup alpha beta = Just (step 0)
where step :: Nat -> Nat
step k = case alpha (encode [beta i | i <- [0..k]]) of
Just n -> n
Nothing -> step (k + 1)
prepend :: Nat -> Baire -> Baire
prepend n beta k | k == 0 = Just n
prepend n beta k | otherwise = beta (k - 1)
multiply :: Baire -> Baire -> Baire
multiply alpha beta n = (lookup alpha) (prepend n beta)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment