Skip to content

Instantly share code, notes, and snippets.

View danidiaz's full-sized avatar

Daniel Díaz Carrete danidiaz

View GitHub Profile
@treeowl
treeowl / BasicNat.hs
Last active December 13, 2023 15:12
Fast total sorting of arbitrary Traversable containers
{-# LANGUAGE DataKinds, TypeFamilies, TypeOperators, GADTs,
ScopedTypeVariables, TypeOperators #-}
-- | Type-level natural numbers and singletons, with proofs of
-- a few basic properties.
module BasicNat (
-- | Type-level natural numbers
Nat (..)
, type (+)
@danidiaz
danidiaz / two_weeks_in_another_city.md
Last active August 10, 2021 19:56
One of my pending pet projects is a "tourism simulation" text adventure with dynamically generated descriptions. These are some related resources that might help.
@mrkgnao
mrkgnao / Eftee.hs
Last active September 23, 2019 15:43
An "optimized" version of ElvishJerricco's free arrow type
{-# LANGUAGE Arrows #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
@tonymorris
tonymorris / free-classy-prisms.hs
Created April 28, 2017 07:35
Free monad with classy prisms on grammar
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE DeriveFunctor #-}
import Control.Lens
import Prelude hiding (readFile, writeFile, print)
import qualified Prelude as Prelude(readFile, writeFile, print)
@winterland1989
winterland1989 / BitTwiddle.hs
Last active July 1, 2017 00:19
BitTwiddle with haskell
{-# LANGUAGE CPP #-}
{-# LANGUAGE MagicHash #-}
-- | This module provide fast memchr implemented with ghc primitives.
--
-- http://lemire.me/blog/2017/01/20/how-quickly-can-you-remove-spaces-from-a-string/
-- https://graphics.stanford.edu/~seander/bithacks.html
-- https://jameshfisher.github.io/2017/01/24/bitwise-check-for-zero-byte.html
--
--
@ChrisPenner
ChrisPenner / LispParser.hs
Last active August 16, 2018 14:22
Lisp Parser in a tweet :)
module LispParser where
import Text.Megaparsec
import Text.Megaparsec.String
import Text.Megaparsec.Lexer hiding (space)
data E=L[E]|S String|N Integer deriving Show
e=(char '('*>(L<$>some e)<*char ')'<|>N<$>integer<|>S<$>some letterChar)<*space::Parser E
@paf31
paf31 / FreeAp.md
Last active September 17, 2019 21:08
FreeAp f is a Comonad

FreeAp f is a Comonad

While thinking about comonads as spaces and Day convolution, I realized an interesting thing. The free applicative functor generated by a comonad f is also a comonad.

The free applicative can be defined in a few different ways, but I like to define it like this:

data FreeApplicative f a = Pure a | Free (Day f (FreeApplicative f) a)
@kuribas
kuribas / towers
Last active August 7, 2017 19:34
reddit towers benchmark
import Criterion.Main
import System.Random
import Data.List
import qualified Data.Vector.Unboxed as U
rainfall1 :: [Int] -> Int
rainfall1 xs = sum (zipWith (-) mins xs)
where
mins = zipWith min maxl maxr
maxl = scanl1 max xs
@romainl
romainl / vanilla-linter.md
Last active October 18, 2025 20:00
Linting your code, the vanilla way

Linting your code, the vanilla way

You may want a linter plugin to lint your code in Vim but you probably don't need it. At least try the built-in way before jumping on the plugin bandwagon.

Defining makeprg

autocmd FileType <filetype> setlocal makeprg=<external command>

This autocommand tells Vim to use <external command> when invoking :make % in a <filetype> buffer. You can add as many similar lines as needed for other languages.