Skip to content

Instantly share code, notes, and snippets.

> putStrLn $ drawVerticalTree (Node g [Node g [], Node g [Node g [], Node g [], Node g []]])
┌───────┐
│ o o . │
│ o x x │
│ . . . │
└───────┘
|
---------------------
/ \
┌───────┐ ┌───────┐
> putStrLn $ drawVerticalTree (Node g [Node g [], Node g [Node g [], Node g []]])
+-----+
|o o .|
|o x x|
|. . .|
+-----+
|
------------
/ \
+-----+ +-----+
Unqualified:
5888 $
4924 .
1762 <$>
1018 <>
777 <*>
468 ^
406 *
367 >>=
[1 of 1] Compiling Main ( Setup.hs, /private/var/folders/nb/8rlykx_x2hj2dgcpnt0js9q40000gn/T/nix-build-old-time-1.1.0.3.drv-0/Main.js_o )
Linking Setup.jsexe (Main)
configuring
configureFlags: --verbose --prefix=/nix/store/jsnqh4qnhcw2dn1b64bjs9h0l1qv7f0l-old-time-1.1.0.3 --libdir=$prefix/lib/$compiler --libsubdir=$pkgid --docdir=/nix/store/7kfjs2v4lfq4vyqfpmv4z7a3ax4zr5aq-old-time-1.1.0.3-doc/share/doc --with-gcc=clang --package-db=/private/var/folders/nb/8rlykx_x2hj2dgcpnt0js9q40000gn/T/nix-build-old-time-1.1.0.3.drv-0/package.conf.d --ghc-option=-optl=-Wl,-headerpad_max_install_names --disable-split-objs --disable-library-profiling --disable-executable-profiling --enable-shared --enable-library-vanilla --enable-executable-dynamic --disable-tests --ghcjs --extra-include-dirs=/nix/store/9vpq5wm8fd8177cpfx6vlvqfrk7kb7aw-libiconv-osx-10.11.6/include --extra-lib-dirs=/nix/store/9vpq5wm8fd8177cpfx6vlvqfrk7kb7aw-libiconv-osx-10.11.6/lib --extra-lib-dirs=/nix/store/sknn9xvnf19fyrwd7axrv3fg31ghadq8-ghc-
@neongreen
neongreen / derivation.hs
Last active November 15, 2020 16:18
MonadBase and MonadBaseControl instances
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
import Control.Concurrent.STM.TVar
import Control.Monad.Reader
import Control.Monad.Base
import Control.Monad.Trans.Control
import Network.HTTP.Client
-- | Connection destination: just host and port.
data Destination = Destination {-# UNPACK #-} !ShortByteString !Int
deriving (Eq, Show)
instance Hashable Destination
-- | Add a per-host hard connection limit. When there are more than N open connections to a
-- host, any new connection to that host will immediately fail with 'PerHostConnectionLimit'.
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
-- | Look up user locally, then in brig, then return the 'UserId'. If either lookup fails, return
-- 'Nothing'. See also: 'Spar.App.createUser'.
--
-- ASSUMPTIONS: User creation on brig/galley is idempotent. Any incomplete creation (because of
-- brig or galley crashing) will cause the lookup here to yield invalid user.
getUser :: SAML.UserRef -> Spar (Maybe UserId)
getUser uref = do
muid <- wrapMonadClient $ Data.getUser uref
case muid of