Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
What's this?

Jason Dagit dagit

💭
What's this?
View GitHub Profile
View Cont.hs
{- 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 Jul 8, 2021
shift + reset example
View Main.hs
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 Aug 4, 2021
LogicT + Streamly for iterative deepening in constant space
View Main.hs
{-# 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
View gist:a214a722a1e91f32eecb642f2bd85d5f
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, )
View print_nmi.lua
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 Feb 17, 2017
Division-free determinant for Integer matrices
View Determinant.hs
-- 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)
View CoreLexer.x
{
{-# OPTIONS -w #-}
module CoreLexer
( Alex(..)
, AlexPosn(..)
, Token(..)
, alexMonadScan
, runAlex
, alexGetInput
) where
View Utils.hs
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
}
View ZipWith.hs
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