Skip to content

Instantly share code, notes, and snippets.

View namin's full-sized avatar

Nada Amin namin

View GitHub Profile
@jonifreeman
jonifreeman / scalatoprolog.md
Created January 30, 2012 09:16
Scala type system -> Prolog
@kmizu
kmizu / Amb.scala
Created March 13, 2012 12:48
Minimal implementation of amb by shift/reset
//scalac -P:continuations:enable
import scala.util.continuations._
object Amb{
def amb[T](elements: T*):T @suspendable = shift{k:(T=>Unit) => elements.foreach(k)}
def block(body : => Unit @suspendable): Unit = reset(body)
def main(args: Array[String]) {
block {
val a = amb(1, 2, 3)
val b = amb("A", "B", "C")
println(a, b)
@swannodette
swannodette / gist:3217582
Created July 31, 2012 14:52
sudoku_compact.clj
;; based on core.logic 0.8-alpha2 or core.logic master branch
(ns sudoku
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn get-square [rows x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in rows [x y])))
@TiarkRompf
TiarkRompf / GenericLifiting.scala
Last active November 30, 2017 16:28
generic class lifting and method forwarders
import language.experimental.macros
import language.dynamics
import scala.reflect.macros._
case class Rep[+T](x:String)
implicit def anyToRep[T](x:T) = new Rep[T](x.toString)
class ShouldLift[T]
@HairyFotr
HairyFotr / gist:4995607
Created February 20, 2013 13:38
Scala Clojure interop wrapper
class ClojureWrap(ns: String, objName: String) {
import clojure.lang.{RT,Var}
import scala.collection.mutable.HashMap
RT.loadResourceScript(objName+".clj")
val obj = ns+"."+objName
val funcs = new HashMap[String, Var]
def /(func: String, a: Any): Object =
funcs.getOrElseUpdate(func, RT.`var`(obj, func)).invoke(a.asInstanceOf[Object])
@avescodes
avescodes / Editing Clojure with Emacs
Last active July 5, 2022 13:32
Get started editing Clojure in Emacs with this basic config.
Check out README.md to get started editing Clojure with Emacs.
@jackrusher
jackrusher / heart-murmur.clj
Last active December 24, 2015 16:09
My first attempt at an aleatoric composition with Overtone. An example of the audio output is here: https://soundcloud.com/jackrusher/heart-murmur
(ns overtone-playground.heart-murmur
(:use overtone.core
overtone.inst.sampled-piano
overtone.samples.piano))
;; (boot-server)
;; (sampled-piano)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Reproducible randomness
@bobatkey
bobatkey / gadts.sml
Created January 5, 2014 18:34
Encoding of GADTs in SML/NJ
(* This is a demonstration of the use of the SML module system to
encode (Generalized Algebraic Datatypes) GADTs via Church
encodings. The basic idea is to use the Church encoding of GADTs in
System Fomega and translate the System Fomega type into the module
system. As I demonstrate below, this allows things like the
singleton type of booleans, and the equality type, to be
represented.
This was inspired by Jon Sterling's blog post about encoding proofs
in the SML module system:
@milessabin
milessabin / gist:aae285025a32fac0f5c1
Last active August 26, 2017 10:28
Trivial type safe heterogenous map using only dependent method types, singleton-typed String literal keys and implicits.
scala> trait Assoc[K] { type V ; val value: V }
defined trait Assoc
scala> def mkAssoc[V0](k: String, v: V0): Assoc[k.type] { type V = V0 } =
| new Assoc[k.type] { type V = V0 ; val value = v }
mkAssoc: [V0](k: String, v: V0)Assoc[k.type]{type V = V0}
scala> implicit def nameAssoc = mkAssoc("Name", "Mary")
nameAssoc: Assoc[String("Name")]{type V = String}
@milessabin
milessabin / gist:c51b6851548dae403abf
Created May 9, 2014 10:11
Type safe selectDynamic without macros
miles@frege:~$ scala
Welcome to Scala version 2.11.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_55).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.language.dynamics
import scala.language.dynamics
scala> case class Assoc[K, V](value: V)
defined class Assoc