Skip to content

Instantly share code, notes, and snippets.

@chrisdone
chrisdone / file-embed-demo.hs
Created August 14, 2019 08:55
File embed expansion demo
> :set -XOverloadedStrings
> :set -XTemplateHaskell
> import Language.Haskell.TH
> $(bsToExp "Hello, World" >>= stringE . show)
"AppE (VarE GHC.IO.Unsafe.unsafePerformIO) (AppE (AppE (VarE Data.ByteString.Unsafe.unsafePackAddressLen) \
\(LitE (IntegerL 12))) (LitE (StringPrimL [72,101,108,108,111,44,32,87,111,114,108,100])))"
>
> :set -ddump-splices
@chrisdone
chrisdone / cleaner-forms.hs
Last active August 12, 2019 09:10
forms experimentation type family
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
import Data.Bifunctor
@chrisdone
chrisdone / ShuffleGraph.hs
Last active August 7, 2019 11:26
Shuffle a graph
{-# LANGUAGE ScopedTypeVariables #-}
module Data.Graph.Shuffle where
-- | Shuffle a graph into a randomly sorted list, preserving
-- topological order.
{-
> quickCheckWith stdArgs {maxSuccess=10000} prop_identity
@chrisdone
chrisdone / StableShuffle.hs
Last active August 6, 2019 17:02
Graph stable shuffle
{-# LANGUAGE PartialTypeSignatures #-}
module StableShuffle where
import Control.Monad
import Control.Monad.Random
import Data.Bifunctor
import Data.List
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Ord
@chrisdone
chrisdone / StableShuffle.hs
Created August 6, 2019 15:54
StableShuffle.hs
{-# LANGUAGE PartialTypeSignatures #-}
module StableShuffle where
import Control.Monad
import Control.Monad.Random.Class
import Data.List
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Ord
import System.Random.Shuffle
This file has been truncated, but you can view the full file.
chris@precision:~/Work/chrisdone/prj$ stack build -v
Version 2.2.0, Git revision 896869ee79d82e3bd9bead30d610ac2bf580cd99 (dirty) (7790 commits) PRE-RELEASE x86_64 hpack-0.31.2
2019-07-31 14:16:17.668130: [debug] Checking for project config at: /home/chris/Work/chrisdone/prj/stack.yaml
2019-07-31 14:16:17.668320: [debug] Loading project config file stack.yaml
2019-07-31 14:16:17.674494: [debug] SELECT COUNT(*) FROM "last_performed" WHERE ("action"=?) AND ("timestamp">=?); [PersistInt64 1,PersistUTCTime 2019-07-30 13:16:17.674439 UTC]
2019-07-31 14:16:17.675171: [debug] Using package location completions from a lock file
2019-07-31 14:16:17.877293: [debug] Asking for a supported GHC version
2019-07-31 14:16:17.877678: [debug] Installed tools:
- ghc-8.2.2
- ghc-8.6.3
chris@precision:~/Work/chrisdone/prj$ stack build -v
Version 2.2.0, Git revision 896869ee79d82e3bd9bead30d610ac2bf580cd99 (dirty) (7790 commits) PRE-RELEASE x86_64 hpack-0.31.2
2019-07-31 13:32:31.396846: [debug] Checking for project config at: /home/chris/Work/chrisdone/prj/stack.yaml
2019-07-31 13:32:31.397084: [debug] Loading project config file stack.yaml
2019-07-31 13:32:31.405902: [debug] SELECT COUNT(*) FROM "last_performed" WHERE ("action"=?) AND ("timestamp">=?); [PersistInt64 1,PersistUTCTime 2019-07-30 12:32:31.40582 UTC]
2019-07-31 13:32:31.406606: [debug] Using package location completions from a lock file
2019-07-31 13:32:31.568532: [debug] Asking for a supported GHC version
2019-07-31 13:32:31.569087: [debug] Installed tools:
- ghc-8.2.2
- ghc-8.6.3
{-
> :t $$(named [|| map ||])
$$(named [|| map ||])
:: TypedName
((ghc-prim-0.5.3:GHC.Types.Any -> ghc-prim-0.5.3:GHC.Types.Any)
-> [ghc-prim-0.5.3:GHC.Types.Any]
-> [ghc-prim-0.5.3:GHC.Types.Any])
> $$(named [|| map ||])
TypedName GHC.Base.map
@chrisdone
chrisdone / AesonPreservingKeyOrder.hs
Created July 8, 2019 10:39
AesonPreservingKeyOrder.hs
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE CPP #-}
-- | A version of aeson that parses with key order preserved.
--
-- Copyright: (c) 2019 Hasura, Inc.
-- (c) 2011-2016 Bryan O'Sullivan
-- (c) 2011 MailRank, Inc.
module Data.Parser.Json
@chrisdone
chrisdone / GADT_JSON.hs
Last active June 28, 2019 13:39
Read/write GADTs as JSON
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ExtendedDefaultRules #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}