Fancy Haskell advice: Add recursion to a strongly-typed stack machine
Haskell Community [Unofficial]
March 12, 2026
So I have worked out the scheme I want and implemented it, so far without compile-time stack-underflow guarantees. They will be an interesting challenge to add, any pointers appreciated!
github.com/AriFordsham/stack-machine
src/StackMachine.hs
main
{-# LANGUAGE ImpredicativeTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
module StackMachine where
import Data.Bits ((.&.))
import Data.List (uncons)
import Data.Foldable (foldlM)
import Control.Monad.Identity (Identity)
import Data.Fin (Fin, fin0, fin1, fin2, fin3, fin4)
import Data.Type.Nat (Nat (S), Nat1, Nat5)
import Data.Vec.Lazy (Vec (..), (!))
data Instr = And | Add | Eq | Dup | Swap | Push Int | Pop
deriving (Show)
This file has been truncated. show original
Discussion in the ATmosphere