Skip to content

Instantly share code, notes, and snippets.

View Kraks's full-sized avatar
:octocat:

Guannan Wei Kraks

:octocat:
View GitHub Profile
@Kraks
Kraks / repl.cpp
Last active December 15, 2015 21:29
/* A simple Read–eval–print-loop example
*/
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(int argc, char **argv)
/* convert argv into a list
*/
#include <iostream>
#include <string>
#include <list>
#include <vector>
using namespace std;
@Kraks
Kraks / LCS.py
Created September 29, 2013 17:21
#!/usr/bin/env python
# find an LCS (Longest Common Subsequence).
# *public domain*
def find_lcs_len(s1, s2):
m = [ [ 0 for x in s2 ] for y in s1 ]
for p1 in range(len(s1)):
for p2 in range(len(s2)):
if s1[p1] == s2[p2]:
if p1 == 0 or p2 == 0:
@Kraks
Kraks / recursive_max_min.sml
Created October 9, 2013 11:26
Recursive Max and Min
fun compare(xs: int list, f: int * int -> int) =
if length xs = 2
then f(hd xs, hd(tl xs))
else f(hd xs, compare(tl xs, f))
fun max(x: int, y: int) =
if x < y
then y
else x
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
@Kraks
Kraks / monad.rkt
Created September 27, 2015 01:57 — forked from tonyg/monad.rkt
Monads in Racket
#lang racket/base
;; Monads in Racket, including polymorphic bind, return and fail.
;; Haskell-like do-notation.
(provide define-monad-class
(struct-out monad-class)
monad?
gen:monad
monad->monad-class
determine-monad
@Kraks
Kraks / .vimrc
Last active June 18, 2022 01:54
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
@Kraks
Kraks / question4.hs
Last active September 8, 2016 16:39
-- Homework 2
-- Abstract transfer function for unsigned subtraction for
-- 4-bit abstract values in the interval abstract domain
-- run command: `ghci question4.hs`
import Data.List
import Prelude hiding (subtract)
type Interval = (Integer, Integer)
# Path to your oh-my-zsh installation.
export ZSH=/Users/kraks/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
#ZSH_THEME="robbyrussell"
ZSH_THEME="mytheme"

Advanced Functional Programming with Scala - Notes

Copyright © 2016-2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x