This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(*took examples from https://youtu.be/NIq3qLaHCIs*) | |
let printf = Printf.printf | |
let example1 = | |
let alphabet = ['a'; 'b'; 'c'; 'd'; 'e'; 'f'] in | |
match alphabet with | |
| a :: b :: _ -> | |
printf "a = %c and b = %c\n" a b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let combinations combine l l' = | |
CCList.cartesian_product [l; l'] | |
|> CCList.map (fun [p; p'] -> combine p p') | |
let paths xmax ymax = | |
let rec aux x y prev_paths = | |
if x > xmax || y > ymax then [] | |
else if x = xmax && y = ymax then prev_paths | |
else | |
let next_paths = List.flatten [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(*Example from http://libdill.org/ rewritten in Lwt*) | |
open Lwt | |
let rec worker s = | |
Lwt_io.printl s >>= fun () -> | |
Lwt_unix.sleep @@ Random.float 0.5 >>= fun () -> | |
worker s | |
let main = | |
let _ = worker "Hello!" in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module type S = sig | |
type priv | |
type exposed = [ `A | `Priv of priv ] | |
val mkB : unit -> priv | |
val f : priv -> priv | |
val g : priv -> string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Num = struct | |
type t = [ `F of float | `I of int ] | |
let to_float = function | |
`F f -> f | |
| `I i -> float i | |
let add n n' = match n, n' with | |
`F f, `F f' -> `F (f +. f') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun yank-to-x-clipboard () | |
(interactive) | |
(if (region-active-p) | |
(progn | |
(shell-command-on-region | |
(region-beginning) (region-end) | |
"xsel -pi") | |
(message "Yanked region to clipboard!") | |
(deactivate-mark)) | |
(message "You havn't marked any text."))) |