Grilled Cheese

ExploreLog inSign up
Terms of UsePrivacy PolicyCommunity StandardsHelpGet the app

Grilled Cheese is a product of Village Compute

Version devBuilt at: 2026-12-03 22:42:33 EST

PhotosVideosAllPeople
LatestRanked
Photo, no description
Photo, no description
Photo, no description
data Instruction
    = AddToAccumulator Int
    | SubFromAccumulator Int

initState :: Int
initState = 0

runMachine :: Instruction -> State Int Int
runMachine instr = do
  -- run instruction
  case instr of
    AddToAccumulator n -> do
      modify' (+n)
    SubFromAccumulator n -> do
      modify' (subtract n)
  -- return accumulator
  get

-- A circuit using signals ..
machineCircuit ::
  HiddenClockResetEnable dom =>
  Signal dom Instruction ->
  Signal dom Int
machineCircuit =
    -- .. running the state monad with 'mealyS' :o
    mealyS runMachine initState
Photo, no description
Photo, no description
Photo, no description
Screenshot from the Waterfall CAD Playground with code on the left and the rendered model of the wheel on the right
controller = toSMC @(F (Packet ** Target)) @(F (Drive ** Report ** Quality)) \(packet, target) -> SMC.do
  let decode' = lift @(F Packet) @(F Sample :** F Quality :** F Debug) decode
      control' = lift @(F Error :** F State) @(F Drive :** F State) control
  (sample, quality, _debug) <- decode' packet
  let error = difference -< (target, calibrate -< sample)
  rec (drive, state) <- control' (SMC.recast error SMC.** (delay -< state))
  returnA -< (drive, monitor -< (sample, quality, drive), quality)