Skip to content

Instantly share code, notes, and snippets.

@chrisdone
chrisdone / foldl-vs-foldl-strict.md
Last active November 11, 2019 19:49
Strict fold vs regular fold

Duet's folds example

Duet has this folding example:

data List a = Nil | Cons a (List a)
foldr = \f z l ->
  case l of
    Nil -> z
    Cons x xs -> f x (foldr f z xs)
-- | Execute the steps.
execute :: [SomeStep] -> RIO MainEnv ()
execute steps = do
resources <- newIORef mempty
mapRIO
(\MainEnv {logger} -> ExecuteEnv {logger = logger . ExecuteLog, resources})
(mapM_ executeSomeStep steps)
@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