Skip to content

Instantly share code, notes, and snippets.

@aymanosman
aymanosman / inequality.rkt
Created March 7, 2019 13:56
inequality.rkt
#lang pie
;; Prelude
(claim +
(-> Nat Nat Nat))
(define +
(lambda (n m)
(rec-Nat n
m
@aymanosman
aymanosman / ind-List.rkt
Last active March 6, 2019 00:52
ind-List.rkt
#lang pie
;; Exercises on ind-Nat from Chapter 10 of The Little Typer
;; Prelude
(claim +
(-> Nat Nat Nat))
(define +
@aymanosman
aymanosman / equality-Nat.rkt
Last active February 21, 2019 20:57
equality-Nat.rkt
#lang pie
;; Exercises on Nat equality from Chapter 8 and 9 of The Little Typer
(claim +
(-> Nat Nat
Nat))
(define +
(λ (n m)
@aymanosman
aymanosman / list-elimination.rkt
Last active January 23, 2019 08:25
The Little Typer: Exercises for Chapters 4 and 5
#lang pie
;; Exercises on Pi types and using the List elimiator from Chapters 4 and 5
;; of The Little Typer
;;
;; Some exercises are adapted from assignments at Indiana University
(claim elim-Pair
(Π ((A U)
(D U)
@aymanosman
aymanosman / Exercise 3.4.rkt
Last active February 4, 2020 01:42
The Little Typer Exercise 3.4
#lang pie
(claim >
(-> Nat Nat Nat))
(define >
(lambda (n)
(rec-Nat n
(the (-> Nat Nat) (lambda (m) 0))
(lambda (n-1 n-1>)
(lambda (m)
@aymanosman
aymanosman / 4clojure-30.clj
Last active November 26, 2018 23:32
4clojure-30.clj
(defn f
([xs] (if (empty? xs) () (f (first xs) (rest xs))))
([x xs]
(cond
(empty? xs) (list x)
:else
(let [y (first xs)]
(cond
(= x y)
@aymanosman
aymanosman / Makefile
Created April 2, 2017 02:48
Haskell Makefile
HC = ghc
HC_OPTS = -cpp $(EXTRA_HC_OPTS)
SRCS = Main.lhs Foo.lhs Bar.lhs
OBJS = Main.o Foo.o Bar.o
.SUFFIXES : .o .hs .hi .lhs .hc .s
cool_pgm : $(OBJS)
rm -f $@
# Sexp equivalent, modulo infix arithmetic expression
# (defmodule M
# (def foo (lol)
# 2+lol))
# Starting from the "true", most verbose form and applying syntactic rules to
# obtain the final form
# "true" expression, notice there are no vararg functions
defmodule(M,
@aymanosman
aymanosman / joi_objectid.js
Last active August 3, 2016 10:11
Validate ObjectIds with Joi
m = require('mongojs')
J = require('joi')
x = J.string().hex().length(24)
i = m.ObjectId().toString()
// '57a1c20202ccc41cd8d84834'
x.validate(i)
// { error: null, value: '57a1c20202ccc41cd8d84834' }
@aymanosman
aymanosman / elm-events.elm
Created October 30, 2015 12:23
Demonstrate custom event capture in Elm
import Dict exposing (Dict)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import String
import Debug exposing (log)
import Json.Decode as Json
import Signal exposing (Address)
import StartApp.Simple
import Json.Decode as Json