Skip to content

Instantly share code, notes, and snippets.

View dagit's full-sized avatar
💭
What's this?

Jason Dagit dagit

💭
What's this?
View GitHub Profile
{- cabal:
build-depends: base
build-depends: transformers
ghc-options: -threaded
-}
import Control.Concurrent (myThreadId, threadDelay, forkOS)
import Control.Monad (forever, void)
import Control.Monad.IO.Class (liftIO)
@dagit
dagit / Main.hs
Created July 8, 2021 19:03
shift + reset example
module Main where
-- | We're using Cont directly from transformers package
import Control.Monad.Trans.Cont
import Control.Monad.Trans.Writer
import Control.Monad.Trans.Class (lift)
-- | We're going to be doing a lot of 'print'ing from inside 'ContT'
-- so let's give ourselves a conviennt way to do it.
cPrint = lift . putStrLn
@dagit
dagit / Main.hs
Last active August 4, 2021 14:47
LogicT + Streamly for iterative deepening in constant space
{-# language FlexibleInstances #-}
{-# language TypeFamilies #-}
{-# language FlexibleContexts #-}
module Main where
import Streamly
import qualified Streamly.Prelude as S
import Control.Applicative
import Control.Monad.Logic
import Data.Foldable
2019-05-25T14:15:48 default - Warning: QMetaObject::connectSlotsByName: No matching signal for on_pushButton_clicked() (:0, )
2019-05-25T14:15:48 default - Warning: QLayout: Attempting to add QLayout "" to USB2SnesStatut "usb2snesStatut", which already has a layout (:0, )
2019-05-25T14:15:48 default - Warning: QLayout: Attempting to add QLayout "" to SNESClassicStatut "snesclassicStatut", which already has a layout (:0, )
2019-05-25T14:15:48 ConsoleSwitcher - Debug: Mode is "USB2Snes" (:0, )
2019-05-25T14:15:49 MainUI - Debug: Savestate2snes "0.4.2" (:0, )
2019-05-25T14:15:49 MainUI - Debug: Mode changed 0 (:0, )
2019-05-25T14:15:49 MainUI - Debug: Loading games (:0, )
2019-05-25T14:15:49 HandleStuff - Debug: Loading games 1 (:0, )
2019-05-25T14:15:49 HandleStuff - Debug: "Super Metroid" (:0, )
2019-05-25T14:15:49 MainUI - Debug: LastGameLoaded was : "Super Metroid" (:0, )
local function print_nmi()
-- 10: give it a few frames to warm up, why not?
if emu.framecount() == 10 then
-- TODO: use gui.text(0, 0, foo) instead of print(foo)
print("" .. (memory.readbyteunsigned(0xfffa) + memory.readbyteunsigned(0xfffb)*256))
end
end
emu.registerbefore(print_nmi)
-- load it with:
@dagit
dagit / Determinant.hs
Created February 17, 2017 18:02
Division-free determinant for Integer matrices
-- This is a direct copy&paste from Bird's Pearls of Functional Algorithm Design
import Data.List (transpose)
trimult xss yss = zipWith (map . dp) xss (submats (transpose yss))
submats :: [[a]] -> [[[a]]]
submats [[x ]] = [[[x ]]]
submats xss = xss : submats (map tail (tail xss))
dp xs ys = sum (zipWith (*) xs ys)
{
{-# OPTIONS -w #-}
module CoreLexer
( Alex(..)
, AlexPosn(..)
, Token(..)
, alexMonadScan
, runAlex
, alexGetInput
) where
module Utils where
import Data.Map (Map)
import qualified Data.Map as M
data Heap a = Heap
{ hNumObjs :: Int
, hUnused :: [Addr]
, hMap :: Map Addr a
}
module Data.ZipWith where
import Prelude hiding (zipWith, succ)
infixl 5 <<
(<<) :: [a -> b] -> [a] -> [b]
(f:fs) << (a:as) = f a : (fs << as)
_ << _ = []
succ :: ([b] -> c) -> [a -> b] -> [a] -> c