Skip to content

Instantly share code, notes, and snippets.

@soupi
soupi / bfs.hs
Created May 10, 2020 19:48
shortest path using bfs
{-# LANGUAGE ViewPatterns, TupleSections #-}
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Seq
import Control.Monad.Except
type User = String
type From = User
type To = User
@soupi
soupi / client.hs
Created July 1, 2020 14:14
Echo server/client haskell
module Main (main) where
import Control.Monad (forever, unless)
import qualified Data.ByteString.Char8 as C
import Network.Socket
import Network.Run.TCP (runTCPClient)
import Network.Socket.ByteString (recv, sendAll)
import System.IO (hFlush, stdout)
main :: IO ()
@soupi
soupi / moving-gc.txt
Last active January 25, 2021 21:47
output of -sstderr for running nyx-game with --nonmoving-gc
5,249,078,184 bytes allocated in the heap
234,375,952 bytes copied during GC
9,022,600 bytes maximum residency (8 sample(s))
1,733,392 bytes maximum slop
24 MiB total memory in use (0 MB lost due to fragmentation)
Tot time (elapsed) Avg pause Max pause
Gen 0 5100 colls, 0 par 0.323s 0.328s 0.0001s 0.0005s
Gen 1 8 colls, 0 par 0.020s 0.020s 0.0025s 0.0056s
@soupi
soupi / upload.hs
Created November 13, 2021 14:32
upload a file to http server
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import Web.Scotty
import Control.Monad.IO.Class
import Network.Wai.Middleware.RequestLogger
import Network.Wai.Middleware.Static
import Network.Wai.Parse
@soupi
soupi / eval_with_reader.hs
Last active January 21, 2022 16:23
How to use Reader and IORef for static scope and mutation
{-# options_ghc -Wall #-}
{-# language LambdaCase #-}
-- | Run repl with:
--
-- > cabal repl --build-depends containers --build-depends mtl
--
-- or
--
-- > stack exec --package containers --package mtl -- ghci
@soupi
soupi / kinds.hs
Last active July 17, 2024 14:04
Kind inference using unification-base constraint solving.
#!/usr/bin/env cabal
{- cabal:
build-depends: base, mtl, containers, uniplate
ghc-options: -Wall
-}
-- | An example of a kind inference for data types using
-- unification-based constraint solving.
--
-- See the blog post:
@soupi
soupi / kinds.hs
Created October 10, 2023 09:02
kind inference with rows/variants
#!/usr/bin/env cabal
{- cabal:
build-depends: base, mtl, containers, uniplate
ghc-options: -Wall
-}
-- | An example of a kind inference for data types using
-- unification-based constraint solving.
--