Skip to content

Instantly share code, notes, and snippets.

View ramirez7's full-sized avatar
💗
Grey hairs are visible / I'm kinda of miserable, too

Armando Ramirez ramirez7

💗
Grey hairs are visible / I'm kinda of miserable, too
View GitHub Profile
@ramirez7
ramirez7 / time-ghci
Last active March 13, 2024 14:57
Get the _real_ time of stuff in ghci
:{
let ghciTime cmd = do
let mkVar n u = "ghciTime_" ++ n ++ "_" ++ show (Data.Unique.hashUnique u)
startVar <- mkVar "start" <$> Data.Unique.newUnique
resVar <- mkVar "res" <$> Data.Unique.newUnique
endVar <- mkVar "end" <$> Data.Unique.newUnique
pure $ unlines
[ startVar ++ " <- Data.Time.getCurrentTime"
, resVar ++ "<- " ++ cmd
, endVar ++ " <- Data.Time.getCurrentTime"
@ramirez7
ramirez7 / hlist-gadt.hs
Created February 20, 2024 22:24
HList via GADTs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
module HList.GADT where
import Data.Kind
data HList (ts :: [Type]) where
HNil :: HList '[]
HCons :: forall t ts. t -> HList ts -> HList (t ': ts)
@ramirez7
ramirez7 / gadt-X.hs
Last active February 5, 2024 21:19
G X XX
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE LambdaCase #-}
import Data.Kind
data I a
data X a
data XX
@ramirez7
ramirez7 / th-ghci
Last active January 11, 2024 19:09
ghci command to run top-level TH. Thanks /u/affinehyperplane for the trick! https://www.reddit.com/r/haskell/comments/18vkivp/comment/kh9byjd/?utm_source=reddit&utm_medium=web2x&context=3
:{
let doTH code = do
u <- Data.Unique.newUnique
let decls = "ghciTH_" ++ show (Data.Unique.hashUnique u)
pure $ unlines
[ unwords ["let", decls, "=", code]
, "() = ();" ++ decls
]
:}
concat(zipWith replicate [1,2,1,0] "cold")
-- Desugar string literal to [Char]
concat(zipWith replicate [1,2,1,0] ['c', 'o', 'l', 'd'])
-- https://hackage.haskell.org/package/base-4.19.0.0/docs/src/GHC.List.html#zipWith
-- Rewritten to not use the "go" helper, zipWith is:
-- zipWith f [] _ = []
-- zipWith f _ [] = []
-- zipWith f (x:xs) (y:ys) = f x y : zipWith f xs ys
@ramirez7
ramirez7 / col.md
Created November 15, 2023 20:26 — forked from vurtun/col.md

screen0 screen1

package main
import (
"fmt"
"os"
"os/signal"
"sync/atomic"
"syscall"
)
@ramirez7
ramirez7 / .gitignore
Last active September 30, 2023 20:58
liquid-intro
dist-newstyle/*
.liquid/*
@ramirez7
ramirez7 / time-log.sh
Last active September 11, 2023 19:45
time-log.sh
# Keep track of build times in a lightweight way
# The log file is based on branch name
function time-log-file() {
echo "$(time-log-dir)/time.$(git rev-parse --abbrev-ref HEAD | sed s#/#--#g).log"
}
function time-log-dir() {
echo "$(git rev-parse --show-toplevel)/.time-logs"
}
[armando@nixos:~]$ ghci
GHCi, version 9.2.8: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/armando/.ghci
λ :seti -XDeriveGeneric
λ import GHC.Generics
λ data P = P Int Bool String deriving Generic
λ data S = S1 | S2 | S3 deriving Generic
λ data R = R { x :: Int, y :: Bool, z :: String } deriving Generic
λ data SR = S1 { x1 :: Int } | S2 { y2 :: Bool} | S3 { z3 :: String } deriving Generic
λ :t from