Skip to content

Instantly share code, notes, and snippets.

@PkmX
PkmX / Interpolate.hs
Last active January 24, 2019 09:13
GHC Source Plugin for Data.String.Interpolate
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Interpolate (plugin) where
import GhcPlugins
import HsSyn
import qualified Data.Generics as SYB
plugin :: Plugin
@PkmX
PkmX / .foo.c
Last active December 10, 2018 18:29
x86_64 soft float kernel module POC
#include <stdint.h>
double ker(void) { return 42.0; }
// Can't link with compiler-rt because their built-ins also use SSE registers.
// A super naive double to int conversion function that only works on small positive integers.
int64_t naive_dtoi(double x) {
uint64_t u = (union { double d; uint64_t u; }) { x }.u;
return ((u & 0xfffffffffffff) | (1ULL << 52)) >> (1075 - ((u >> 52) & 0x7ff));
}
#include <iostream>
#include <string>
struct table {
std::string s;
table() {}
~table() { std::cout << this->s; }
table(const int n) : s{std::to_string(n)} {}
table(std::string&& s_) : s{std::move(s_)} {}
[Version]
AppVersion=5.3-656-gb8440087
Version=331
[General]
Rank=0
ColorLabel=0
InTrash=false
[Exposure]
@PkmX
PkmX / Main.hs
Last active March 6, 2017 08:33
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import Data.Reflection
newtype QDouble = QDouble Double
newtype Step = Step Double
@PkmX
PkmX / NamedTuple.hs
Last active October 21, 2021 10:20 — forked from chrisdone/NamedTuple.hs
Using type-level symbols and overloaded labels to make named tuples
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedLabels #-}
@PkmX
PkmX / Main.hs
Last active July 29, 2016 22:52
Pattern synonyms for compound-types
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
@PkmX
PkmX / DynT.hs
Last active March 30, 2016 19:50
DynT
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Data.DynT where
@PkmX
PkmX / loeb.md
Last active January 9, 2019 15:59
Löb with error handling

Löb with error handling

löb is a well-known function in Haskell for implementing spreadsheet-like behaviors and tying the knot. It is defined as:

loeb :: Functor f => f (f a -> a) -> f a
loeb fs = xs
  where xs = fmap ($ xs) fs
Dungeon Crawl Stone Soup version 0.18-a0-1212-g3cecdf7 (tiles) character file.
1315647 pkmx the Demonologist (level 26, 182/182 HPs)
Began as a Gargoyle Summoner on Feb 12, 2016.
Was the Champion of Sif Muna.
Escaped with the Orb
... and 3 runes on Feb 13, 2016!
The game lasted 09:29:09 (109962 turns).