Skip to content

Instantly share code, notes, and snippets.

View igstan's full-sized avatar

Ionuț G. Stan igstan

View GitHub Profile
/* A better way to tag types?
*
* 1) object Time: here we are distinguishing between different uses of a Long,
* yet there is no boxing whatsoever.
*
* main calls start: ()J
* main calls timed: (Function0, J)
* Function0 gives up the result: ()J
* timed calls now: ()J
* timed calls elapsed$extension: (JJ)J
@joseanpg
joseanpg / cps.scm
Created April 20, 2013 09:05
LISP in small pieces: CPS Transformation (5.9)
;; http://books.google.es/books?id=81mFK8pqh5EC&pg=PA177#v=onepage&q&f=false
;; http://pagesperso-systeme.lip6.fr/Christian.Queinnec/WWW/LiSP.html
;; src/chap5f.scm
(define (cps e)
(if (pair? e)
(case (car e)
((quote) (cps-quote (cadr e)))
((if) (cps-if (cadr e) (caddr e) (cadddr e)))
((begin) (cps-begin (cdr e)))
@dscleaver
dscleaver / Fib.scala
Created February 27, 2013 14:45
Port of http://t.co/KvoY7PDGSg. Created in a Scala IDE worksheet.
import scalaz._
import Scalaz._
object monads {
def fix[A](f: (=> A) => A): A = f(fix(f)) //> fix: [A](f: => A => A)A
type Gen[A] = (=> A) => A
def gFib: Gen[Int => Int] = (self) => n =>
@desandro
desandro / require-js-discussion.md
Created January 31, 2013 20:26
Can you help me understand the benefit of require.js?

I'm having trouble understanding the benefit of require.js. Can you help me out? I imagine other developers have a similar interest.

From Require.js - Why AMD:

The AMD format comes from wanting a module format that was better than today's "write a bunch of script tags with implicit dependencies that you have to manually order"

I don't quite understand why this methodology is so bad. The difficult part is that you have to manually order dependencies. But the benefit is that you don't have an additional layer of abstraction.


@vmarquez
vmarquez / ReaderMonad.cs
Last active February 20, 2020 20:30
This is an example of using the Reader Monad for Dependency Injection using LINQ in C#. I learned about this from Tony Morris and Rúnar Bjarnason's video here: http://www.youtube.com/watch?v=ECPGTUa1WAI To figure out the (slightly weird) SelectMany peculiarities I found http://mikehadlow.blogspot.com/2011/01/monads-in-c-4-linq-loves-monads.html
//Reader Monad and its extension class to give it SelectMany(bind/flatMap) capabilities for use in LINQ queries
public static class ReaderMonadExt
{
public static ReaderMonad<T, C> SelectMany<T, A, B, C>(this ReaderMonad<T, A> rm, Func<A, ReaderMonad<T, B>> bindf, Func<A, B, C> select)
{
return new ReaderMonad<T, C>(t =>
{
var a = rm.Run(t);
return select(a, bindf(a).Run(t));
});
@joeriks
joeriks / RoslynDynamicCompilation.cs
Created December 28, 2012 07:44
Add a piece of dynamically compiled code in memory with the help of Roslyn. (After this the Greeter class will be available and can be run from example from the immediate window in visual studio).
public static void AddGreeter()
{
AddInmemory("Greeter", @"using System;
class Greeter
{
public string Greet()
{
return ""Hello World"";
}
@larsrh
larsrh / kleislist.ml
Created November 17, 2012 20:12
GADTs in OCaml, part 2
module type Monad = sig
type 'a m
val bind : 'a m -> ('a -> 'b m) -> 'b m
val return: 'a -> 'a m
end
@joseanpg
joseanpg / comments.txt
Created November 4, 2012 12:56
Understanding cool-tree.aps
Datatype ->
class Datatype_class : public tree_node
constructor_of_Datatype ->
class constructor_class : public Datatype_class {
...
constructor_class(...)
Datatype constructor( par1, par2, ... ) {
return new constructor_class(par1, par2, ...);
@vu3rdd
vu3rdd / wat-py.txt
Created October 23, 2012 09:58
Python scoping..
Some notes on the python scope:
Python has a weird scoping problem, which stems from its intention to create a nice
surface syntax and perhaps to satisfy the imperative programming paradigm. This
affects the semantics of the Python programs in unintuitive ways.
Consider the following code:
A.
@jlongster
jlongster / gist:3881008
Created October 12, 2012 19:28
js destructuring macro
// Note: there are bugs in hygienic renaming, so this doesn't work all the time yet.
macro varr {
case [$var (,) ...] = $expr => {
var i = 0;
var arr = $expr;
$(var $var = arr[i++];) ...
}