Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mstksg's full-sized avatar

Justin Le mstksg

View GitHub Profile
@mstksg
mstksg / gist:aa70c9182c387e6f67b1
Last active August 29, 2015 14:03
Home-made IO+State Monad
andThen :: (s -> IO (a, s)) -> (s -> IO (b, s)) -> (s -> IO (b, s))
andThenWith :: (s -> IO (a, s)) -> (a -> (s -> IO (b, s))) -> (s -> IO (b, s))
-- type synonym:
--
-- > type MIOS s a = s -> IO (s, a)
@mstksg
mstksg / SHO.hs
Created July 31, 2014 05:05
Example of stepping/running an Wire with constant dt
{-# LANGUAGE Arrows #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
module Main (main) where
import Control.Wire
import FRP.Netwire.Move
import Control.Arrow
import Prelude hiding ((.), id, mapM_)
@mstksg
mstksg / PIDs.md
Last active August 29, 2015 14:04
Comparison of PID controller implementation approaches, and a case for a compositional, denotative, locally stateful style

PID Controller: A comparison of approaches

And a case for a compositional, denotative, and locally stateful style.

High Level Description

@mstksg
mstksg / ExprGADT.hs
Last active August 29, 2015 14:25
Type checked lambdas
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
import System.Random
import Control.Monad.Random
import Control.Monad
metroStep :: (RandomGen g) => (Double -> Double) -> Double -> Double -> Rand g Double
metroStep p step x = do
dx <- getRandomR (-step, step)
let
newx = x + dx
p0 = p x
@mstksg
mstksg / Postgresql Runtime Error
Last active December 20, 2015 19:19
Runtime error on selectDistinct on many-to-many join with sorting. No error if ran with sqlite bindings. Also, select (not distinct) works fine.
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE OverloadedStrings #-}
@mstksg
mstksg / assertion dsl
Last active December 22, 2015 20:19
Assertion DSL for complex conditional
import Data.Maybe (isJust)
assert :: Bool -> Maybe ()
assert True = Just ()
assert False = Nothing
checkAssertions :: Maybe () -> Bool
checkAssertions = isJust
checkMatch :: Person -> Person -> Bool
@mstksg
mstksg / dead-code-tests.hs
Created November 13, 2013 21:21 — forked from anonymous/dead-code-tests.hs
Three files, one with only main, one with main + non-referenced IO object, one with main + referenced IO object (technically, one with a larger main IO object). The non-referenced IO object is never compiled, as the resulting object files have the same md5sum.
-- test1.hs
-- No dead code: compiles to 1.22M executable
-- with stripped .o 1320 byes
-- .o file md5sum: 35ccd1647c772a5757fba3ae8bfa6542
main :: IO ()
main = getLine >>= print
-- test2.hs
-- With dead code: compiles to 1.22M executable

Keybase proof

I hereby claim:

  • I am mstksg on github.
  • I am mstksg (https://keybase.io/mstksg) on keybase.
  • I have a public key whose fingerprint is 1BB5 2738 56F8 1236 7977 2D4F 7250 9247 67D5 7F1C

To claim this, I am signing this object:

{-# language DataKinds, PolyKinds, ScopedTypeVariables, UndecidableInstances,
FlexibleInstances, FlexibleContexts, GADTs, TypeFamilies, RankNTypes,
LambdaCase, TypeOperators, ConstraintKinds #-}
import GHC.TypeLits
import Data.Proxy
import Data.Singletons.Prelude
import Data.Singletons.Decide
import Data.Constraint