Skip to content

Instantly share code, notes, and snippets.

View ndmitchell's full-sized avatar

Neil Mitchell ndmitchell

View GitHub Profile
@ndmitchell
ndmitchell / HSE.hs
Last active July 30, 2017 21:31
Threepenny GUI's
{-# LANGUAGE RecursiveDo #-}
module Main(main) where
import qualified Graphics.UI.Threepenny as UI
import Graphics.UI.Threepenny.Core
import Graphics.UI.Threepenny.Editors
import Data.Profunctor
import Language.Haskell.Exts
@ndmitchell
ndmitchell / Binary.hs
Created August 31, 2017 20:40
Binary serialisation of existentials
{-# LANGUAGE StaticPointers #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Data.Binary
import Data.Typeable
import System.IO.Unsafe
import GHC.StaticPtr
@ndmitchell
ndmitchell / hse-atom.hs
Last active November 15, 2017 22:28
HSE analysis of atoms
{-# LANGUAGE ScopedTypeVariables #-}
-- Note that 1 vs -1 is one of the few things that matters!!!
import Language.Haskell.Exts
import Language.Haskell.Exts.Util
import Data.Data
import Control.Monad
import Data.List
@ndmitchell
ndmitchell / bug.hs
Created November 16, 2017 21:41
Exceptions from "wrapper" functions
-- ghc bug.hs c.c && bug
module Main(main) where
import Control.Concurrent
import Control.Monad
import Foreign.C
import Foreign.Ptr
foreign import ccall apply :: FunPtr (CString -> IO CString) -> CString -> IO CString
-- To use:
-- Place this file in compiler/.ghci
-- stack exec --stack-yaml=../hadrian/stack.yaml -- ghci -package-db=../_build/stage0/bootstrapping.conf
:set -ibackpack
:set -ibasicTypes
:set -icmm
:set -icodeGen
:set -icoreSyn
:set -ideSugar
@ndmitchell
ndmitchell / Monad.hs
Created March 24, 2018 21:45
Shake Action as a GADT
{-# LANGUAGE CPP #-}
{-# LANGUAGE GeneralizedNewtypeDeriving, GADTs, DeriveFunctor, ScopedTypeVariables, BangPatterns #-}
module Development.Shake.Internal.Core.Monad(
RAW, Capture, runRAW,
getRO, getRW, getsRO, getsRW, putRW, modifyRW,
catchRAW, tryRAW, throwRAW,
unmodifyRW, captureRAW,
) where
@ndmitchell
ndmitchell / Rec.hs
Created May 11, 2018 18:43
4-file GHC bug
{-# LANGUAGE DisambiguateRecordFields #-}
import Rec3
import Rec2
bug = AnDouble{an=1}
@ndmitchell
ndmitchell / GhcApi.hs
Last active June 20, 2018 19:09
GHC optimisation differences
-- Program used to compile LensOpt.hs using the GHC API
import GHC
import GhcPlugins
import GHC.Paths
main = runGhc (Just libdir) $ do
setTargets []
dflags <- getSessionDynFlags
setSessionDynFlags dflags{hscTarget = HscNothing}
@ndmitchell
ndmitchell / File.hs
Created July 1, 2018 20:23
Suspending 2
suspending :: forall i k v. Ord k => Scheduler Monad i i k v
suspending rebuilder tasks target store = fst $ execState (build target) (store, Set.empty)
where
build :: k -> State (Store i k v, Set k) ()
build key = case tasks key of
Nothing -> return ()
Just task -> do
done <- gets snd
when (key `Set.notMember` done) $ do
value <- gets (getValue key . fst)
data Foo where
Bar :: Foo
Baz :: Foo
deriving Show
-- seems to be parsed as:
data Foo where {
Bar :: Foo;
Baz :: foo}