Skip to content

Instantly share code, notes, and snippets.

View danidiaz's full-sized avatar

Daniel Díaz Carrete danidiaz

View GitHub Profile
@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)
@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
@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
--
--
@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)
@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 #-}
@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.
@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 (+)
-- The meta-circular interpreter from section 5 of Reynolds's Definitional
-- Interpreters for Higher Order Programming Languages
-- (http://www.cs.uml.edu/~giam/91.531/Textbooks/definterp.pdf)
data EXP
= CONST Const
| VAR Var
| APPL Appl
| LAMBDA Lambda
| COND Cond
@dariusf
dariusf / Phantom.java
Created February 5, 2017 00:27
Phantom types in Java
class Files {
static void read(File<Open> file) {}
static File<Open> open(File<Closed> file) {
return null;
}
static File<Closed> close(File<Open> file) {
return null;
}
}