Skip to content

Instantly share code, notes, and snippets.

@jproyo
jproyo / Format.hs
Created December 1, 2021 14:35
First NoRedInk Tech Interview
module Format.Stdout where
import Control.Program
import qualified Data.Map.Strict as M
import Relude
output :: Histogram -> IO ()
output =
mapM_ (\(k, v) -> putStrLn $ show k ++ " " ++ replicate (fromIntegral v) '#') . M.assocs
@jproyo
jproyo / basic_proof.tex
Last active October 4, 2020 12:20
Basic Proposicional Logic Proof
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Five ways to prove $P \implies Q$
\begin{itemize}
\item \textbf{Direct Proof}: $P \implies Q$
\item \textbf{Proof by Contrapositive}: $\neg Q \implies \neg P$
@jproyo
jproyo / TypeOperatorsExample.hs
Created September 1, 2020 08:02
Type Operators Brittany
{-# LANGUAGE TypeOperators #-}
module HsOpTy where
import GHC.TypeLits
-- brittany-disable-next-binding
type Foo =
Int :
'[]
@jproyo
jproyo / Test.hs
Created July 20, 2020 07:10
Toy Example for decoding JSON from Stdin
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE OverloadedStrings #-}
module Test where
import Data.Aeson
import Data.ByteString.Lazy as BL
import Data.Text as T
data User = User { name :: Text
@jproyo
jproyo / a.md
Created March 8, 2020 09:29 — forked from monadplus/profiling_haskell.md
Profiling in Haskell

You'll generally want to look at:

  • heap
  • stack
  • gc profiles

Do not get bogged down in microoptimizations before you've assessed any macro optimizations that are available. IO and the choice of algorithm dominate any low level changes you may make. In the end you have to think hard about your code!

Topos> For example, if i see that a particular pure function is taking a  long time relative to the rest of the code, and that it's Text, and I'm seeing ARR_WORDS rise linearly in the heap, I probably have a thunk-based memory leak. This is knowledge you build up over time.
@jproyo
jproyo / haskell_spacemacs_tips.md
Last active June 14, 2019 08:05
Tips for working with Emacs in Haskell. Usefull commands

Tips for Spacemacs with Haskell

  • C-c C-l => Load ghci in place with the current buffer
  • <SPC> C-r => Reformat region hindent
  • , F => Format imports
  • , f => hindent
  • , r b => hlint refactor buffer
  • , r s => suggestions
  • , r r => refactor at point
  • , h i => info at point
@jproyo
jproyo / .stylish-haskell.yaml
Last active June 14, 2019 21:17
My Haskell Stylish custom config
# stylish-haskell configuration file
# ==================================
# The stylish-haskell tool is mainly configured by specifying steps. These steps
# are a list, so they have an order, and one specific step may appear more than
# once (if needed). Each file is processed by these steps in the given order.
steps:
# Convert some ASCII sequences to their Unicode equivalents. This is disabled
# by default.
# - unicode_syntax:
@jproyo
jproyo / deps.sh
Created May 20, 2019 10:49
Install deps for spacemacs
#!/bin/bash
stack install apply-refact hlint stylish-haskell hasktags hoogle intero hindent ispell
brew install ispell
@jproyo
jproyo / Data.hs
Last active May 19, 2022 16:04
Tagless Final Encoding in Haskell Example
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
module Data where
type UserName = String
data DataResult = DataResult String
deriving (Eq, Show)
class Monad m => Cache m where