Skip to content

Instantly share code, notes, and snippets.

package main
import "fmt"
type SomeError struct { string }
var err *SomeError
func (x *SomeError) Error()string { return x.string }
func MaybeLog(err error) {
@paulp
paulp / cast.go
Last active November 17, 2017 00:00
/** TL;DR Of course we want to savagely truncate our data!
* You know we want that because earlier you saw us cast between
* same-sized types (because you offer no other way) and all casts
* are the same.
*/
package main
import . "fmt"
type Foo int16
@bcardiff
bcardiff / ast_dump.cr
Created June 30, 2015 21:58
Crystal AST dump
require "compiler/crystal/**"
class Object
def dump_inspect(io, level)
io << " " * level
to_s(io)
io << " :: " << self.class
end
end
@runarorama
runarorama / gist:33986541f0f1ddf4a3c7
Created May 7, 2015 14:06
Higher-kinded types encoded as path-dependent types
trait λ {
type α
}
trait Functor extends λ {
type α <: λ
def map[A,B](x: α { type α = A })(f: A => B): α { type α = B }
}

Hacking Dyalog APL # 1

Dyalog APL is a great tool but the interface for working in an interactive session is rather poor. Editing previous lines by moving the cursor to some other location is rather painful. Of course Dyalog APL isn't allowed to use the great readline library. But it is not too difficult to replace the officiel ncurses interface by some more modern readline-based one as long as you do it with an external tool.

What you will get is:

  • a modern readline-based input;
  • a great history system (persistent accross sessions if you wish);
  • the ability to launch your favorite editor on the fly for editing a more complex line of input (or defining a traditional function) whenever you want;
  • leaving Dyalog APL with the Ctrl-D signal;
@paulp
paulp / constantish.scala
Created May 6, 2015 19:11
classic scala
// Wherein scala assigns the constant type String("a") to a string "b".
// Idea by retronym in https://issues.scala-lang.org/browse/SI-7730
scala> def f[A <: AnyRef: scala.reflect.ClassTag](x: Any) = x match { case (a: A, x: (a.type forSome { type T })) => ((a, x)) }
warning: there was one feature warning; re-run with -feature for details
f: [A <: AnyRef](x: Any)(implicit evidence$1: scala.reflect.ClassTag[A])(A, A)
scala> final val x = "a"
x: String("a") = a
scala> f[x.type](x -> x)
@eatonphil
eatonphil / gist:7d57257f65673b343441
Created May 5, 2015 11:47
Bot Dumps Beautiful Uncompiled Spam On My Blog
{
{I have|I’ve} been {surfing|browsing} online more than {three|3|2|4} hours today, yet
I never found any interesting article like yours. {It’s|It is}
pretty worth enough for me. {In my opinion|Personally|In my view},
if all {webmasters|site owners|website owners|web owners} and bloggers made good content as you did, the {internet|net|web} will be {much more|a lot more} useful than ever before.|
I {couldn’t|could not} {resist|refrain from} commenting.
{Very well|Perfectly|Well|Exceptionally well} written!|
{I will|I’ll} {right away|immediately} {take hold of|grab|clutch|grasp|seize|snatch} your {rss|rss feed} as I {can not|can’t} {in finding|find|to find} your {email|e-mail} subscription {link|hyperlink} or {newsletter|e-newsletter} service.
Do {you have|you’ve} any? {Please|Kindly} {allow|permit|let} me {realize|recognize|understand|recognise|know} {so that|in order that} I {may
just|may|could} subscribe. Thanks.|
identification division.
program-id. hangman.
data division.
working-storage section.
01 state.
05 word pic A(100).
05 word-length pic 9(3).
05 guess pic A.
05 guesses occurs 256 times pic 9.
{
multi sub infix:<cmp>(42, "Life, The Universe, and Everything") { Order::Same }
{{{{{
sub trylift () {
nonlifter;
lifter;
}
trylift;
package p {
trait Functor[F[X]] extends Any { def fmap[A, B](x: A => B): F[A] => F[B] }
trait Pointed[F[X]] extends Functor[F] { def pure[A](x: A): F[A] }
trait Monad[F[X]] extends Pointed[F] { def join[A](x: F[F[A]]): F[A] }
trait Copointed[F[X]] extends Functor[F] { def copure[A](x: F[A]): A }
trait Comonad[F[X]] extends Copointed[F] { def cojoin[A](x: F[A]): F[F[A]] }
trait Bimonad[F[X]] extends Monad[F] with Comonad[F]
sealed trait Monadic[F[X], A] extends Any
final case class Pure[F[X], A](x: A) extends Monadic[F, A]