Skip to content

Instantly share code, notes, and snippets.

@aavogt
aavogt / main.hs
Last active March 8, 2023 17:02
gi-gtk and hint threads
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE LambdaCase #-}
module Main (main) where
import qualified GI.Gdk as Gdk
import qualified GI.Gtk as Gtk
import Reactive.Banana.Frameworks
import Data.GI.Base (on)
import Language.Haskell.Interpreter as Hint
@aavogt
aavogt / zipper.rs
Last active February 21, 2023 02:31
struct Zipper<'a, T> {
up : Vec<&'a mut T>,
focus : &'a mut T,
down : Vec<&'a mut T>,
}
impl<'a, T> Zipper<'a, T> {
fn focus_n(&'a mut self, n: i32) -> Option<&mut Self> {
let mut x = self.focus_top()?;
// n focus downs from the top
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
type family Remove v xs where
Remove x (x ': xs) = Remove x xs
Remove x (y ': xs) = y ': Remove x xs
Remove x '[] = '[]
@aavogt
aavogt / StaticVars.hs
Last active January 7, 2023 19:59
ImplicitParams emulating `static`
{-# LANGUAGE TemplateHaskell #-}
module StaticVars where
import Language.Haskell.TH
import Data.IORef
import System.IO.Unsafe (unsafePerformIO)
import Control.Monad.IO.Class
staticVarsPrefix = "v"
{-# LANGUAGE StandaloneDeriving, FlexibleContexts, UndecidableInstances #-}
-- zippers is probably a better answer
import Control.Lens
import Data.Maybe
-- with index
data WI m = WI (Index m) m
deriving instance (Show m, Show (Index m)) => Show (WI m)
mkwi' :: Ixed m => Index m -> m -> WI m
-- we can implement drawN_ in terms of drawN, but not the other way around
--
drawN_ :: MonadState s m => (forall b. [b] -> m [b]) -> m ()
drawN_ = drawN
drawN :: MonadState s m => ([Card] -> m [Card]) -> m ()
drawN shuffle = _
@aavogt
aavogt / overpay.hs
Last active December 12, 2018 00:19
import Control.Lens
{- | in monopoly deal you have to pay more than you owe,
if you don't have exact change
Ex. if you have $3, $2 $2 $2, $1 $1 bills, and owe 4:
>>> overpay 4 [(3,1),(2,3),(1,2)]
[([(1,2),(2,1)],[(2,2),(3,1)],0),
([(2,2)],[(1,2),(2,1),(3,1)],0),
@aavogt
aavogt / Main.hs
Created May 18, 2016 17:12
lexicographic sorting doesn't go faster when the sorting function sees more structure
module Main where
import Criterion.Main
import Criterion
import Data.List
import Data.Foldable (toList)
import Data.Random
import Data.Monoid ((<>))
import qualified Data.IntMap as IM
@aavogt
aavogt / HistogramProb.hs
Last active May 11, 2016 19:31
histograms are almost applicative
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE TemplateHaskell #-}
module HistogramProb where
import qualified Data.Map as M
import Control.Lens
@aavogt
aavogt / xmonad.hs
Last active May 5, 2016 17:15 — forked from lierdakil/xmonad.hs
A toy implementation of fully monadic config
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FunctionalDependencies #-}