Skip to content

Instantly share code, notes, and snippets.

View rizo's full-sized avatar

Rizo rizo

  • Porto (Portugal)
View GitHub Profile
@rizo
rizo / generic_contains.go
Created February 27, 2017 16:11
Generic implementation of the `contains` function without runtime cost. No dependencies, runs on any unix machine with a go compiler!
// Generic implementation of the `contains` function.
// No dependencies, runs on any unix machine with a go compiler!
//
// Build instruction:
//
// $ go generate
// $ go run gen.go
//
package main
@rizo
rizo / particals.go
Created February 15, 2017 15:13
Partical function application in Go: both implicit and explicit.
func sum(x int, y int) {
return x + y
}
func sum_partial(x int) {
return func(y int) {
return x + y
}
}
@rizo
rizo / switch-const.c
Last active February 14, 2017 17:00
How switch is implemented? Both examples were compiled with `clang -O0 -S switch.c -o switch.s`.
#include <stdio.h>
int main() {
switch (42) {
case 0:
puts("not 42");
break;
case 42:
puts("yes 42");
break;
@rizo
rizo / max1.scala
Last active October 26, 2016 23:02
def max(input: List[Int]): Option[Int] = {
def loop(result: Option[Int], list: List[Int]): Option[Int] = {
(result, list) match {
case (_, Nil) => result
case (None, x::xs) => loop(Some(x), xs)
case (Some(prev), x::xs) if x > prev => loop(Some(x), xs)
case (_, _::xs) => loop(result, xs)
}
}
@rizo
rizo / clojure-examples.clj
Last active September 29, 2016 20:28
Some random code examples for my friends.
; Returns -1 if x is 2 and x otherwise.
(defn check-two [x]
(if (= x 2)
-1
x))
(assert (check-two 1) 1)
(assert (check-two 2) -1)
@rizo
rizo / hello.c
Created September 7, 2016 14:42
Says hello.
#include <stdio.h>
int main(int argc, char *argv[]) {
puts("Hello!");
return 0;
}
@rizo
rizo / fold-syntax.md
Last active September 3, 2016 22:19
Syntax processing rules for Fold

Syntax Rules

Atoms

-> eval 42
 = 42
-> eval 3.14
 = 3.14
@rizo
rizo / pure.md
Last active August 2, 2016 08:14

Pure – a small and modular base library for OCaml

  • no dependencies
  • minimal and sufficient
  • foundation for functional patterns
  • shared interfaces for interoperability between libraries
  • not opinionated, sufficiently generic and simple to be accepted as common sense by almost any one with good fp background.

Library

Iterators Benchmark

This file contains the benchmark results for different iteration models proposed for inclusion in the OCaml's standard library.

  • Machine: Intel(R) Xeon(R) CPU E3-1245 V2 @ 3.40GHz (x86_64)
  • Compiler: 4.03.0 (-O3 -unbox-closures -unbox-closures-factor 20)

Implementations

| name | description | simplified type |

@rizo
rizo / javascript-reason-fold.md
Created May 20, 2016 01:48
Javascript, Reason and Fold – syntax comparison.

Basic Language Primitives

JavaScript Reason Fold
3
3
3
3.1415 
 3.1415 
 3.1415 
"Hello world!" 
"Hello world!" 
"Hello world!" 
'Hello world!' Strings must use " Strings must use "