Skip to content

Instantly share code, notes, and snippets.

@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.
@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'

Kernel keywords

  • apply/2
  • apply/3
  • cond/1
  • destructure/2
  • exit/1
  • if/2
  • in/2
  • match?/2
@bitemyapp
bitemyapp / gist:8739525
Last active May 7, 2021 23:22
Learning Haskell

Hi, looking for scalac flags?

This gist has been upgraded to a blog post here.

@chaitanyagupta
chaitanyagupta / _reader-macros.md
Last active July 4, 2025 22:26
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.

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 {
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] {
@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
@moritz
moritz / call-positional-by-name.pl
Created May 18, 2014 13:57
Fill positional arguments by name (Perl 6)
use v6;
sub t ($x, $y, :$label = 'sum') {
say "$label: ", $x + $y;
}
sub namecall(&c, *@pos, *%named is rw) {
my %name-to-idx;
for &c.signature.params.kv -> $idx, $p {
next if $p.named;