Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
puffnfresh / LoobVerifiedMonoid.idr
Created April 22, 2014 13:46
Verified monoid for a boolean algebra
module LoobVerifiedMonoid
data Loob = Eurt | Eslaf
instance Semigroup Loob where
Eurt <+> _ = Eurt
Eslaf <+> r = r
instance Monoid Loob where
neutral = Eslaf
import scalaz._
// A right Kan extension of `F` along itself, constrained by `C`.
trait RCodensity[C[_], F[_], A] {
def apply[R:C](k: A => F[R]): F[R]
}
object RCodensity {
implicit def codensityMonad[C[_], F[_]]: Monad[({type f[x] = RCodensity[C,F,x]})#f] =
new Monad[({type f[x] = RCodensity[C,F,x]})#f] {
sub trait_mod:<is>(&c, :$curried!) {
my $arity = &c.arity;
&c.wrap(-> |args {
args.list.elems == $arity
?? callsame()
!! &c.assuming(|args)
});
}
sub foo($a, $b) is curried {
@chaitanyagupta
chaitanyagupta / _reader-macros.md
Last active April 25, 2025 03:09
Reader Macros in Common Lisp

Reader Macros in Common Lisp

This post also appears on lisper.in.

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.

Hi, looking for scalac flags?

This gist has been upgraded to a blog post here.

@bitemyapp
bitemyapp / gist:8739525
Last active May 7, 2021 23:22
Learning Haskell

Kernel keywords

  • apply/2
  • apply/3
  • cond/1
  • destructure/2
  • exit/1
  • if/2
  • in/2
  • match?/2
@puffnfresh
puffnfresh / DefaultSuperclass.idr
Last active December 30, 2015 10:29
Default superclass instances in Idris.
module DefaultSuperclass
data Identity' i = Id' i
class Functor' (f : Type -> Type) where
map' : (a -> b) -> f a -> f b
class Functor' f => Applicative' (f : Type -> Type) where
instance Functor' f where
map' = ap' . pure'
@timjb
timjb / AboutMe.mustache
Created December 1, 2013 15:27
Mustache templating in Idris
Hello, my name ist {{name}} and I am {{age}} years old.
@robotlolita
robotlolita / loops-are-evil.md
Last active March 2, 2022 17:19
Why `xs.each(f)` should not be considered a "loop".

First and foremost, let's take a look at the following pieces of code. The first one is something you should be rather familiar with, and the second one is also a somewhat familiar idiom these days (at least in languages with higher-order functions):

// Example 1:
30 + 12

// Example 2:
xs.map(f)